Skip to content

Commit

Permalink
fix: signout properly
Browse files Browse the repository at this point in the history
NextAuth doesn't have a way to signout a user from the server side.

This is the easiest way until they add that
  • Loading branch information
hazimoarafa committed Nov 16, 2024
1 parent 8efe9a3 commit 6d9124a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function AdminLayout({
children: React.ReactNode;
}) {
const session = await auth();
if (!session) return redirect("/api/auth/signout");
if (!session) return redirect("/api/signout");

if (!session.roles.includes("lh-user-tasks-admin")) redirect("/");

Expand Down
13 changes: 13 additions & 0 deletions ui/src/app/api/signout/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use client";

import { signOut } from "next-auth/react";
import { useLayoutEffect } from "react";

export default function Logout() {
useLayoutEffect(() => {
// TODO: Once NextAuth adds a way to signout on the server we need to switch.
signOut({ redirect: true, callbackUrl: "/" });
}, []);

return null;
}
2 changes: 1 addition & 1 deletion ui/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { auth } from "../app/api/auth/[...nextauth]/authOptions";
export async function getClient() {
const session = await auth();

if (!session) redirect("/api/auth/signout");
if (!session) redirect("/api/signout");

return new LittleHorseUserTasksApiClient({
baseUrl: process.env.LHUT_API_URL!,
Expand Down

0 comments on commit 6d9124a

Please sign in to comment.