diff --git a/src/auth/actions.ts b/src/auth/actions.ts index 803b9b8e..477ee0b5 100644 --- a/src/auth/actions.ts +++ b/src/auth/actions.ts @@ -9,6 +9,7 @@ import { signOut, } from '@/auth'; import { PATH_ADMIN_PHOTOS, PATH_ROOT } from '@/site/paths'; +import type { Session } from 'next-auth'; import { redirect } from 'next/navigation'; export const signInAction = async ( @@ -40,3 +41,6 @@ export const signOutAndRedirectAction = async () => signOut({ redirectTo: PATH_ROOT }); export const getAuthAction = () => auth(); + +export const logClientAuthUpdate = (data: Session | null | undefined) => + console.log('Client auth update', data); diff --git a/src/state/AppStateProvider.tsx b/src/state/AppStateProvider.tsx index 9e0a2701..d9967814 100644 --- a/src/state/AppStateProvider.tsx +++ b/src/state/AppStateProvider.tsx @@ -4,7 +4,7 @@ import { useState, useEffect, ReactNode, useCallback } from 'react'; import { AppStateContext } from './AppState'; import { AnimationConfig } from '@/components/AnimateItems'; import usePathnames from '@/utility/usePathnames'; -import { getAuthAction } from '@/auth/actions'; +import { getAuthAction, logClientAuthUpdate } from '@/auth/actions'; import useSWR from 'swr'; import { MATTE_PHOTOS } from '@/site/config'; @@ -38,7 +38,10 @@ export default function AppStateProvider({ const invalidateSwr = useCallback(() => setSwrTimestamp(Date.now()), []); const { data } = useSWR('getAuth', getAuthAction); - useEffect(() => setUserEmail(data?.user?.email ?? undefined), [data]); + useEffect(() => { + setUserEmail(data?.user?.email ?? undefined); + logClientAuthUpdate(data); + }, [data]); const registerAdminUpdate = useCallback(() => setAdminUpdateTimes(updates => [...updates, new Date()])