Add temporary client-side auth logging

This commit is contained in:
Sam Becker 2024-05-11 13:06:18 -05:00
parent 2b692754ec
commit 5180fd7ea6
2 changed files with 9 additions and 2 deletions

View File

@ -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);

View File

@ -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()])