Add sign out to admin menu

This commit is contained in:
Sam Becker 2025-02-26 00:08:22 -06:00
parent 87bd9ff5b1
commit 97d8fef130
4 changed files with 23 additions and 5 deletions

View File

@ -1,8 +1,10 @@
import { auth } from '@/auth'; import { auth } from '@/auth';
import SignInForm from '@/auth/SignInForm'; import SignInForm from '@/auth/SignInForm';
import { PATH_ADMIN } from '@/app/paths'; import { PATH_ADMIN, PATH_ROOT } from '@/app/paths';
import { clsx } from 'clsx/lite'; import { clsx } from 'clsx/lite';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import LinkWithStatus from '@/components/LinkWithStatus';
import { IoArrowBack } from 'react-icons/io5';
export default async function SignInPage() { export default async function SignInPage() {
const session = await auth(); const session = await auth();
@ -17,6 +19,16 @@ export default async function SignInPage() {
'flex items-center justify-center flex-col gap-8', 'flex items-center justify-center flex-col gap-8',
)}> )}>
<SignInForm /> <SignInForm />
<LinkWithStatus
href={PATH_ROOT}
className={clsx(
'flex items-center gap-2.5',
'text-lg',
)}
>
<IoArrowBack className="translate-y-[1px]" />
Home
</LinkWithStatus>
</div> </div>
); );
} }

View File

@ -15,6 +15,8 @@ import { TbPhoto } from 'react-icons/tb';
import { FiTag } from 'react-icons/fi'; import { FiTag } from 'react-icons/fi';
import { BiLockAlt } from 'react-icons/bi'; import { BiLockAlt } from 'react-icons/bi';
import AdminAppInfoIcon from './AdminAppInfoIcon'; import AdminAppInfoIcon from './AdminAppInfoIcon';
import { PiSignOutBold } from 'react-icons/pi';
import { signOutAndRedirectAction } from '@/auth/actions';
export default function AdminAppMenu({ export default function AdminAppMenu({
className, className,
@ -87,6 +89,10 @@ export default function AdminAppMenu({
} }
}, },
shouldPreventDefault: false, shouldPreventDefault: false,
}, {
label: 'Sign Out',
icon: <PiSignOutBold size={15} className="translate-x-[1px]" />,
action: signOutAndRedirectAction,
}]} }]}
ariaLabel="Admin Menu" ariaLabel="Admin Menu"
/> />

View File

@ -10,7 +10,7 @@ import {
signIn, signIn,
signOut, signOut,
} from '@/auth'; } from '@/auth';
import { PATH_ADMIN_PHOTOS, PATH_ROOT } from '@/app/paths'; import { PATH_ADMIN_PHOTOS, PATH_SIGN_IN } from '@/app/paths';
import type { Session } from 'next-auth'; import type { Session } from 'next-auth';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
@ -41,8 +41,8 @@ export const signInAction = async (
redirect(formData.get(KEY_CALLBACK_URL) as string || PATH_ADMIN_PHOTOS); redirect(formData.get(KEY_CALLBACK_URL) as string || PATH_ADMIN_PHOTOS);
}; };
export const signOutAndRedirectAction = async () => export const signOutAndRedirectAction = async (redirectTo = PATH_SIGN_IN) =>
signOut({ redirectTo: PATH_ROOT }); signOut({ redirectTo });
export const getAuthAction = async () => auth(); export const getAuthAction = async () => auth();

View File

@ -59,7 +59,7 @@ export default function MoreMenu({
)} )}
> >
{header && <div className={clsx( {header && <div className={clsx(
'px-2 py-1.5 text-medium uppercase', 'px-2 pt-3 pb-2 text-dim uppercase',
'text-sm', 'text-sm',
)}> )}>
{header} {header}