diff --git a/src/admin/AdminAppMenu.tsx b/src/admin/AdminAppMenu.tsx
index a487398e..43b22056 100644
--- a/src/admin/AdminAppMenu.tsx
+++ b/src/admin/AdminAppMenu.tsx
@@ -131,8 +131,7 @@ export default function AdminAppMenu({
}, {
label: 'Sign Out',
icon: ,
- action: () => signOutAction()
- .then(() => clearAuthStateAndRedirect?.(false)),
+ action: () => signOutAction().then(clearAuthStateAndRedirect),
});
return (
diff --git a/src/auth/actions.ts b/src/auth/actions.ts
index 1f0ba968..60a4c0fe 100644
--- a/src/auth/actions.ts
+++ b/src/auth/actions.ts
@@ -10,7 +10,7 @@ import {
signIn,
signOut,
} from '@/auth';
-import { PATH_ADMIN_PHOTOS, PATH_SIGN_IN } from '@/app/paths';
+import { PATH_ADMIN_PHOTOS } from '@/app/paths';
import type { Session } from 'next-auth';
import { redirect } from 'next/navigation';
@@ -44,9 +44,6 @@ export const signInAction = async (
export const signOutAction = async () =>
signOut({ redirect: false });
-export const signOutAndRedirectAction = async (redirectTo = PATH_SIGN_IN) =>
- signOut({ redirectTo });
-
export const getAuthAction = async () => auth();
export const logClientAuthUpdate = async (data: Session | null | undefined) =>
diff --git a/src/state/AppState.ts b/src/state/AppState.ts
index 64648fa5..174b7c95 100644
--- a/src/state/AppState.ts
+++ b/src/state/AppState.ts
@@ -39,7 +39,7 @@ export type AppStateContext = {
setUserEmail?: Dispatch>
isUserSignedIn?: boolean
isUserSignedInEager?: boolean
- clearAuthStateAndRedirect?: (shouldRedirect?: boolean) => void
+ clearAuthStateAndRedirect?: () => void
// ADMIN
adminUpdateTimes?: Date[]
registerAdminUpdate?: () => void
diff --git a/src/state/AppStateProvider.tsx b/src/state/AppStateProvider.tsx
index 2039f0e6..b4be8d11 100644
--- a/src/state/AppStateProvider.tsx
+++ b/src/state/AppStateProvider.tsx
@@ -20,8 +20,8 @@ import {
clearAuthEmailCookie,
hasAuthEmailCookie,
} from '@/auth/client';
-import { useRouter } from 'next/navigation';
-import { PATH_SIGN_IN } from '@/app/paths';
+import { useRouter, usePathname } from 'next/navigation';
+import { isPathAdmin, PATH_SIGN_IN } from '@/app/paths';
import { INITIAL_UPLOAD_STATE, UploadState } from '@/admin/upload';
export default function AppStateProvider({
@@ -31,6 +31,8 @@ export default function AppStateProvider({
}) {
const router = useRouter();
+ const pathname = usePathname();
+
const { previousPathname } = usePathnames();
// CORE
@@ -117,18 +119,16 @@ export default function AppStateProvider({
}
}, [userEmail, refreshAdminData, adminData]);
- console.log({ userEmail, isUserSignedIn, isUserSignedInEager });
-
const registerAdminUpdate = useCallback(() =>
setAdminUpdateTimes(updates => [...updates, new Date()])
, []);
- const clearAuthStateAndRedirect = useCallback((shouldRedirect = true) => {
+ const clearAuthStateAndRedirect = useCallback(() => {
setUserEmail(undefined);
setIsUserSignedInEager(false);
clearAuthEmailCookie();
- if (shouldRedirect) { router.push(PATH_SIGN_IN); }
- }, [router]);
+ if (isPathAdmin(pathname)) { router.push(PATH_SIGN_IN); }
+ }, [router, pathname]);
const startUpload = useCallback((onStart?: () => void) => {
if (uploadInputRef.current) {