Refine admin auth handling
This commit is contained in:
parent
a79ec4f078
commit
14ccc20f7a
@ -22,8 +22,8 @@ export const hasAuthEmailCookie = () =>
|
||||
export const clearAuthEmailCookie = () =>
|
||||
deleteCookie(KEY_AUTH_EMAIL);
|
||||
|
||||
export const isCredentialsSignInError = (error: any) =>
|
||||
(error.message || `${error}`).includes(KEY_CREDENTIALS_SIGN_IN_ERROR);
|
||||
export const isCredentialsSignInError = (error?: any) =>
|
||||
(error?.message || `${error}`).includes(KEY_CREDENTIALS_SIGN_IN_ERROR);
|
||||
|
||||
export const generateAuthSecret = () => fetch(
|
||||
'https://generate-secret.vercel.app/32',
|
||||
|
||||
@ -18,7 +18,6 @@ import { AdminData, getAdminDataAction } from '@/admin/actions';
|
||||
import {
|
||||
storeAuthEmailCookie,
|
||||
clearAuthEmailCookie,
|
||||
isCredentialsSignInError,
|
||||
getAuthEmailCookie,
|
||||
} from '@/auth';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
@ -125,12 +124,10 @@ export default function AppStateProvider({
|
||||
setUserEmailEager(getAuthEmailCookie());
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (authError) {
|
||||
if (auth === null || authError) {
|
||||
setUserEmail(undefined);
|
||||
setUserEmailEager(undefined);
|
||||
if (isCredentialsSignInError(authError)) {
|
||||
clearAuthEmailCookie();
|
||||
}
|
||||
} else {
|
||||
setUserEmail(auth?.user?.email ?? undefined);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user