Clear cookie when server rejects auth check
This commit is contained in:
parent
56aaf14c7c
commit
afa34f9b03
@ -19,6 +19,9 @@ export const clearAuthEmailCookie = () =>
|
||||
export const hasAuthEmailCookie = () =>
|
||||
Boolean(getCookie(KEY_AUTH_EMAIL));
|
||||
|
||||
export const isCredentialsSignInError = (error: any) =>
|
||||
(error.message || `${error}`).includes(KEY_CREDENTIALS_SIGN_IN_ERROR);
|
||||
|
||||
export const generateAuthSecret = () => fetch(
|
||||
'https://generate-secret.vercel.app/32',
|
||||
{ cache: 'no-cache' },
|
||||
|
||||
@ -19,6 +19,7 @@ import {
|
||||
storeAuthEmailCookie,
|
||||
clearAuthEmailCookie,
|
||||
hasAuthEmailCookie,
|
||||
isCredentialsSignInError,
|
||||
} from '@/auth';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { isPathAdmin, PATH_ROOT } from '@/app/paths';
|
||||
@ -126,6 +127,9 @@ export default function AppStateProvider({
|
||||
if (authError) {
|
||||
setIsUserSignedInEager(false);
|
||||
setUserEmail(undefined);
|
||||
if (isCredentialsSignInError(authError)) {
|
||||
clearAuthEmailCookie();
|
||||
}
|
||||
} else {
|
||||
setUserEmail(auth?.user?.email ?? undefined);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user