Skip to content

Commit

Permalink
refactor: logout triggers revalidation of / path, lets requirePageAut…
Browse files Browse the repository at this point in the history
…h handle redirect

removes need for props on logout or redirect happening in the logout action.
  • Loading branch information
buckhalt committed May 3, 2024
1 parent ff3b90f commit f33ae4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -117,9 +115,5 @@ export async function logout(disableRedirect?: boolean) {
sessionCookie.attributes,
);

if (disableRedirect) {
return;
}

return redirect('/');
revalidatePath('/');
}
2 changes: 1 addition & 1 deletion components/Feedback/SignOutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SignOutModal = ({
<AlertDialogCancel onClick={() => setOpenSignOutModal(false)}>
Cancel
</AlertDialogCancel>
<AlertDialogAction onClick={() => void logout(true)}>
<AlertDialogAction onClick={() => void logout()}>
Sign Out and Hide Banner
</AlertDialogAction>
</AlertDialogFooter>
Expand Down

0 comments on commit f33ae4e

Please sign in to comment.