+
{response === KEY_CREDENTIALS_SIGN_IN_ERROR &&
Invalid email/password
diff --git a/src/cmdk/CommandKClient.tsx b/src/cmdk/CommandKClient.tsx
index 42fd5501..ef6d9320 100644
--- a/src/cmdk/CommandKClient.tsx
+++ b/src/cmdk/CommandKClient.tsx
@@ -124,7 +124,7 @@ export default function CommandKClient({
const {
isUserSignedIn,
- clearAuthStateAndRedirect,
+ clearAuthStateAndRedirectIfNecessary,
isCommandKOpen: isOpen,
startUpload,
photosCountHidden,
@@ -521,7 +521,9 @@ export default function CommandKClient({
}
adminSection.items.push({
label: 'Sign Out',
- action: () => signOutAction().then(clearAuthStateAndRedirect),
+ action: () => signOutAction()
+ .then(clearAuthStateAndRedirectIfNecessary)
+ .then(() => setIsOpen?.(false)),
});
} else {
adminSection.items.push({
diff --git a/src/state/AppState.ts b/src/state/AppState.ts
index 0ce7039e..590a6ebc 100644
--- a/src/state/AppState.ts
+++ b/src/state/AppState.ts
@@ -39,7 +39,7 @@ export type AppStateContextType = {
setUserEmail?: Dispatch>
isUserSignedIn?: boolean
isUserSignedInEager?: boolean
- clearAuthStateAndRedirect?: () => void
+ clearAuthStateAndRedirectIfNecessary?: () => void
// ADMIN
isCheckingAuth?: boolean
adminUpdateTimes?: Date[]
diff --git a/src/state/AppStateProvider.tsx b/src/state/AppStateProvider.tsx
index 60fca69e..7a18fd76 100644
--- a/src/state/AppStateProvider.tsx
+++ b/src/state/AppStateProvider.tsx
@@ -21,7 +21,7 @@ import {
hasAuthEmailCookie,
} from '@/auth/client';
import { useRouter, usePathname } from 'next/navigation';
-import { isPathAdmin, PATH_SIGN_IN } from '@/app/paths';
+import { isPathAdmin, PATH_ROOT } from '@/app/paths';
import { INITIAL_UPLOAD_STATE, UploadState } from '@/admin/upload';
import { RecipeProps } from '@/recipe';
import { getCountsForCategoriesCachedAction } from '@/category/actions';
@@ -105,6 +105,8 @@ export default function AppStateProvider({
setIsUserSignedInEager(hasAuthEmailCookie());
if (!authError) {
setUserEmail(auth?.user?.email ?? undefined);
+ } else {
+ setIsUserSignedInEager(false);
}
}, [auth, authError]);
const isUserSignedIn = Boolean(userEmail);
@@ -133,11 +135,11 @@ export default function AppStateProvider({
setAdminUpdateTimes(updates => [...updates, new Date()])
, []);
- const clearAuthStateAndRedirect = useCallback(() => {
+ const clearAuthStateAndRedirectIfNecessary = useCallback(() => {
setUserEmail(undefined);
setIsUserSignedInEager(false);
clearAuthEmailCookie();
- if (isPathAdmin(pathname)) { router.push(PATH_SIGN_IN); }
+ if (isPathAdmin(pathname)) { router.push(PATH_ROOT); }
}, [router, pathname]);
// Returns false when upload is cancelled
@@ -187,7 +189,7 @@ export default function AppStateProvider({
setUserEmail,
isUserSignedIn,
isUserSignedInEager,
- clearAuthStateAndRedirect,
+ clearAuthStateAndRedirectIfNecessary,
// ADMIN
adminUpdateTimes,
registerAdminUpdate,