From 97d8fef1306cd0e9ba5cefdf2c4251035756bb4c Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Wed, 26 Feb 2025 00:08:22 -0600 Subject: [PATCH] Add sign out to admin menu --- app/sign-in/page.tsx | 14 +++++++++++++- src/admin/AdminAppMenu.tsx | 6 ++++++ src/auth/actions.ts | 6 +++--- src/components/more/MoreMenu.tsx | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/sign-in/page.tsx b/app/sign-in/page.tsx index 7c3ee0a1..0bccd823 100644 --- a/app/sign-in/page.tsx +++ b/app/sign-in/page.tsx @@ -1,8 +1,10 @@ import { auth } from '@/auth'; 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 { redirect } from 'next/navigation'; +import LinkWithStatus from '@/components/LinkWithStatus'; +import { IoArrowBack } from 'react-icons/io5'; export default async function SignInPage() { const session = await auth(); @@ -17,6 +19,16 @@ export default async function SignInPage() { 'flex items-center justify-center flex-col gap-8', )}> + + + Home + ); } diff --git a/src/admin/AdminAppMenu.tsx b/src/admin/AdminAppMenu.tsx index b11e44b3..499242b5 100644 --- a/src/admin/AdminAppMenu.tsx +++ b/src/admin/AdminAppMenu.tsx @@ -15,6 +15,8 @@ import { TbPhoto } from 'react-icons/tb'; import { FiTag } from 'react-icons/fi'; import { BiLockAlt } from 'react-icons/bi'; import AdminAppInfoIcon from './AdminAppInfoIcon'; +import { PiSignOutBold } from 'react-icons/pi'; +import { signOutAndRedirectAction } from '@/auth/actions'; export default function AdminAppMenu({ className, @@ -87,6 +89,10 @@ export default function AdminAppMenu({ } }, shouldPreventDefault: false, + }, { + label: 'Sign Out', + icon: , + action: signOutAndRedirectAction, }]} ariaLabel="Admin Menu" /> diff --git a/src/auth/actions.ts b/src/auth/actions.ts index 894fb1d6..28d4e0ba 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_ROOT } from '@/app/paths'; +import { PATH_ADMIN_PHOTOS, PATH_SIGN_IN } from '@/app/paths'; import type { Session } from 'next-auth'; import { redirect } from 'next/navigation'; @@ -41,8 +41,8 @@ export const signInAction = async ( redirect(formData.get(KEY_CALLBACK_URL) as string || PATH_ADMIN_PHOTOS); }; -export const signOutAndRedirectAction = async () => - signOut({ redirectTo: PATH_ROOT }); +export const signOutAndRedirectAction = async (redirectTo = PATH_SIGN_IN) => + signOut({ redirectTo }); export const getAuthAction = async () => auth(); diff --git a/src/components/more/MoreMenu.tsx b/src/components/more/MoreMenu.tsx index 968c26d3..b923face 100644 --- a/src/components/more/MoreMenu.tsx +++ b/src/components/more/MoreMenu.tsx @@ -59,7 +59,7 @@ export default function MoreMenu({ )} > {header &&
{header}