feat: rate limiter

This commit is contained in:
Bereket Engida
2024-09-18 14:20:09 +03:00
parent 6c69b804d2
commit 1554e770b4
13 changed files with 478 additions and 42 deletions

View File

@@ -315,9 +315,6 @@ function ChangePassword() {
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M2.5 18.5v-1h19v1zm.535-5.973l-.762-.442l.965-1.693h-1.93v-.884h1.93l-.965-1.642l.762-.443L4 9.066l.966-1.643l.761.443l-.965 1.642h1.93v.884h-1.93l.965 1.693l-.762.442L4 10.835zm8 0l-.762-.442l.966-1.693H9.308v-.884h1.93l-.965-1.642l.762-.443L12 9.066l.966-1.643l.761.443l-.965 1.642h1.93v.884h-1.93l.965 1.693l-.762.442L12 10.835zm8 0l-.762-.442l.966-1.693h-1.931v-.884h1.93l-.965-1.642l.762-.443L20 9.066l.966-1.643l.761.443l-.965 1.642h1.93v.884h-1.93l.965 1.693l-.762.442L20 10.835z"></path></svg>
<span
className="text-sm text-muted-foreground"
onClick={async () => {
}}
>
Change Password
</span>
@@ -376,7 +373,7 @@ function ChangePassword() {
})
setLoading(false);
if (res.error) {
toast.error(res.error.message);
toast.error(res.error.message || "Couldn't change your password! Make sure it's correct");
} else {
setOpen(false);
toast.success("Password changed successfully");

View File

@@ -32,10 +32,15 @@ export async function SignInButton() {
}
function checkOptimisticSession(headers: Headers) {
const guessIsSignIn = headers.get("cookie")?.includes("better-auth.session") || headers.get("cookie")?.includes("__Secure-better-auth.session-token")
return !!guessIsSignIn;
}
export function SignInFallback() {
//to avoid flash of unauthenticated state
const guessIsSignIn = headers().get("cookie")?.includes("better-auth.session") || headers().get("cookie")?.includes("__Secure-better-auth.session-token")
const guessIsSignIn = checkOptimisticSession(headers())
return (
<Link href={
guessIsSignIn ? "/dashboard" : "/sign-in"