From f33ae4eb4de4719fa3a2dfd69751ad05bb567802 Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Fri, 3 May 2024 14:21:15 -0700 Subject: [PATCH] refactor: logout triggers revalidation of / path, lets requirePageAuth handle redirect removes need for props on logout or redirect happening in the logout action. --- actions/auth.ts | 12 +++--------- components/Feedback/SignOutModal.tsx | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/actions/auth.ts b/actions/auth.ts index 9093d3d8..8b09b0d1 100644 --- a/actions/auth.ts +++ b/actions/auth.ts @@ -8,6 +8,7 @@ import { getServerSession, lucia } from '~/utils/auth'; import { redirect } from 'next/navigation'; import { generateIdFromEntropySize } from 'lucia'; import { loginSchema } from '~/schemas/auth'; +import { revalidatePath } from 'next/cache'; export async function signup(formData: FormData) { const username = formData.get('username') as string; @@ -96,11 +97,8 @@ export async function login(formData: FormData) { return redirect('/dashboard'); } -/** - * @param disableRedirect If true, does not redirect to the homepage after logging out - */ -export async function logout(disableRedirect?: boolean) { +export async function logout() { const { session } = await getServerSession(); if (!session) { return { @@ -117,9 +115,5 @@ export async function logout(disableRedirect?: boolean) { sessionCookie.attributes, ); - if (disableRedirect) { - return; - } - - return redirect('/'); + revalidatePath('/'); } diff --git a/components/Feedback/SignOutModal.tsx b/components/Feedback/SignOutModal.tsx index 76a3b8c4..5be33822 100644 --- a/components/Feedback/SignOutModal.tsx +++ b/components/Feedback/SignOutModal.tsx @@ -39,7 +39,7 @@ const SignOutModal = ({ setOpenSignOutModal(false)}> Cancel - void logout(true)}> + void logout()}> Sign Out and Hide Banner