feat: add sign-out redirect URL and enhance sign-in redirect handling

This commit is contained in:
Abhimanyu Saharan
2026-02-09 01:06:33 +05:30
parent f6bcd1ca5f
commit 5630f9b8e8
6 changed files with 123 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveSignInRedirectUrl } from "@/auth/redirects";
describe("resolveSignInRedirectUrl", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("uses env fallback when redirect is missing", () => {
vi.stubEnv("NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL", "/boards");
expect(resolveSignInRedirectUrl(null)).toBe("/boards");
});
it("defaults to /dashboard when no env fallback is set", () => {
expect(resolveSignInRedirectUrl(null)).toBe("/dashboard");
});
it("allows safe relative paths", () => {
expect(resolveSignInRedirectUrl("/dashboard?tab=ops#queue")).toBe(
"/dashboard?tab=ops#queue",
);
});
it("rejects protocol-relative urls", () => {
vi.stubEnv("NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL", "/activity");
expect(resolveSignInRedirectUrl("//evil.example.com/path")).toBe("/activity");
});
it("rejects external absolute urls", () => {
vi.stubEnv("NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL", "/activity");
expect(resolveSignInRedirectUrl("https://evil.example.com/steal")).toBe(
"/activity",
);
});
it("accepts same-origin absolute urls and normalizes to path", () => {
const url = `${window.location.origin}/boards/new?src=invite#top`;
expect(resolveSignInRedirectUrl(url)).toBe("/boards/new?src=invite#top");
});
});