Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/dashboard/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { LoginForm } from "./login-form";
import {
Card,
CardContent,
CardHeader,
} from "@/components/ui/card";
import { BrandLogo } from "@/components/brand-logo";
import { auth } from "@/lib/auth";
import { getBranding } from "@/lib/branding-server";
import { safeCallbackPath } from "@/lib/safe-callback-path";
import {
DEFAULT_CALLBACK_PATH,
safeCallbackPath,
} from "@/lib/safe-callback-path";

export default async function Login({
searchParams,
}: {
searchParams: Promise<{ callbackURL?: string }>;
}) {
const { callbackURL } = await searchParams;
const callbackPath = safeCallbackPath(callbackURL);
const session = await auth.api.getSession({ headers: await headers() });
if (session) {
redirect(
callbackPath === "/login" ? DEFAULT_CALLBACK_PATH : callbackPath,
);
}

const branding = await getBranding();
return (
<main className="grid min-h-svh place-items-center bg-background p-4">
Expand All @@ -22,7 +36,7 @@ export default async function Login({
<BrandLogo url={branding.logo_url} placement="login" />
</CardHeader>
<CardContent>
<LoginForm callbackURL={safeCallbackPath(callbackURL)} />
<LoginForm callbackURL={callbackPath} />
</CardContent>
</Card>
</main>
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/specs/journey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ test.describe.serial("Blue deployment journey", () => {
expect(refreshedClaims.aud).toBeTruthy();
});

test("@smoke authenticated users are redirected away from login", async ({ page }) => {
await loginAsAdmin(page);

await page.goto("/login", { waitUntil: "commit" });
await expect(page).toHaveURL(/\/sessions$/);
await expect(page.getByLabel("Email")).toHaveCount(0);

await page.goto("/login?callbackURL=%2Fgateway", { waitUntil: "commit" });
await expect(page).toHaveURL(/\/gateway$/);
await expect(page.getByLabel("Email")).toHaveCount(0);
});

test("@smoke executable provisioner creates managed gateway access", async () => {
const result = await runCli(home, ["gateway"]);
expect(result.code, result.stderr).toBe(0);
Expand Down
Loading