Add Better Auth admin authentication
This commit is contained in:
@@ -1,18 +1,39 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { getDashboardRedirectPath } from "../lib/route-guards";
|
||||
import {
|
||||
getDashboardRedirectPath,
|
||||
shouldRedirectDashboardRequest,
|
||||
} from "../lib/route-guards";
|
||||
|
||||
test("getDashboardRedirectPath sends guests back to the auth entry", () => {
|
||||
assert.equal(getDashboardRedirectPath(null), "/");
|
||||
test("getDashboardRedirectPath keeps authenticated users on dashboard", () => {
|
||||
assert.equal(getDashboardRedirectPath(true), null);
|
||||
});
|
||||
|
||||
test("getDashboardRedirectPath lets authenticated mock users stay on dashboard", () => {
|
||||
test("getDashboardRedirectPath redirects unauthenticated users to the login page", () => {
|
||||
assert.equal(getDashboardRedirectPath(false), "/login");
|
||||
});
|
||||
|
||||
test("shouldRedirectDashboardRequest protects dashboard paths without authentication", () => {
|
||||
assert.equal(
|
||||
getDashboardRedirectPath({
|
||||
name: "Matthias Meister",
|
||||
email: "matthias@webdev-pipeline.local",
|
||||
}),
|
||||
null,
|
||||
shouldRedirectDashboardRequest("/dashboard", false),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldRedirectDashboardRequest("/dashboard/leads", false),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("shouldRedirectDashboardRequest allows non-dashboard paths without authentication", () => {
|
||||
assert.equal(
|
||||
shouldRedirectDashboardRequest("/audit/example", false),
|
||||
false,
|
||||
);
|
||||
assert.equal(shouldRedirectDashboardRequest("/", false), false);
|
||||
});
|
||||
|
||||
test("shouldRedirectDashboardRequest allows authenticated dashboard sessions", () => {
|
||||
assert.equal(shouldRedirectDashboardRequest("/dashboard", true), false);
|
||||
assert.equal(shouldRedirectDashboardRequest("/dashboard/audit", true), false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user