feat(auth): sign out from the app header
The shell had no way to end a session on shared booth machines; the new button signs out and returns to the login page. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -55,6 +55,19 @@ test.describe("app shell", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("signs out and locks the shell again", async ({ page }) => {
|
||||||
|
await page.setViewportSize({ width: 1024, height: 768 });
|
||||||
|
await signInAs(page, `e2e-signout-${Date.now()}@example.com`);
|
||||||
|
|
||||||
|
await page.goto(`${BASE}/home`);
|
||||||
|
await page.getByRole("button", { name: "Sign out" }).click();
|
||||||
|
await expect(page).toHaveURL(`${BASE}/login`);
|
||||||
|
|
||||||
|
// The session cookie is gone, so the guarded shell bounces back to login.
|
||||||
|
await page.goto(`${BASE}/home`);
|
||||||
|
await expect(page).toHaveURL(`${BASE}/login`);
|
||||||
|
});
|
||||||
|
|
||||||
test("redirects unauthenticated users away from the shell", async ({ page }) => {
|
test("redirects unauthenticated users away from the shell", async ({ page }) => {
|
||||||
await page.setViewportSize({ width: 360, height: 780 });
|
await page.setViewportSize({ width: 360, height: 780 });
|
||||||
await page.goto(`${BASE}/schedule`);
|
await page.goto(`${BASE}/schedule`);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { SystemRole } from "@/auth/roles";
|
import type { SystemRole } from "@/auth/roles";
|
||||||
import { NavTabs, NavRail } from "./nav";
|
import { NavTabs, NavRail } from "./nav";
|
||||||
|
import { SignOutButton } from "./sign-out-button";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App shell: sticky header (app title + mobile tab bar), desktop side rail,
|
* App shell: sticky header (app title + mobile tab bar), desktop side rail,
|
||||||
@@ -28,6 +29,7 @@ export function AppLayout({
|
|||||||
<span className="ml-auto hidden text-xs text-muted-foreground sm:block">
|
<span className="ml-auto hidden text-xs text-muted-foreground sm:block">
|
||||||
Glenloch Baptist Church
|
Glenloch Baptist Church
|
||||||
</span>
|
</span>
|
||||||
|
<SignOutButton />
|
||||||
</div>
|
</div>
|
||||||
<NavTabs className="md:hidden" role={role} />
|
<NavTabs className="md:hidden" role={role} />
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { signOut } from "next-auth/react";
|
||||||
|
import { LogOut } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ends the Auth.js session and returns to the login page. Lives in the app
|
||||||
|
* header so it is reachable from every authenticated screen, on mobile and
|
||||||
|
* desktop alike.
|
||||||
|
*/
|
||||||
|
export function SignOutButton() {
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
async function onSignOut() {
|
||||||
|
setBusy(true);
|
||||||
|
try {
|
||||||
|
await signOut({ callbackUrl: "/login" });
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={onSignOut}
|
||||||
|
disabled={busy}
|
||||||
|
aria-label="Sign out"
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
<LogOut className="h-4 w-4" aria-hidden="true" />
|
||||||
|
<span className="hidden sm:inline">{busy ? "Signing out…" : "Sign out"}</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user