feat: complete MVP foundation auth and dashboard
This commit is contained in:
47
lib/mock-auth.ts
Normal file
47
lib/mock-auth.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export const MOCK_SESSION_COOKIE_NAME = "webdev_pipeline_mock_session";
|
||||
export const MOCK_SESSION_COOKIE_VALUE = "mock-admin";
|
||||
|
||||
export type MockCookieStore = {
|
||||
get: (name: string) => { name: string; value: string } | undefined;
|
||||
};
|
||||
|
||||
export type MockSession = {
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
export const MOCK_ADMIN_SESSION: MockSession = {
|
||||
name: "Matthias Meister",
|
||||
email: "matthias@webdev-pipeline.local",
|
||||
};
|
||||
|
||||
export function hasMockSession(cookieStore: MockCookieStore) {
|
||||
return (
|
||||
cookieStore.get(MOCK_SESSION_COOKIE_NAME)?.value === MOCK_SESSION_COOKIE_VALUE
|
||||
);
|
||||
}
|
||||
|
||||
export function getMockSession(cookieStore: MockCookieStore) {
|
||||
return hasMockSession(cookieStore) ? MOCK_ADMIN_SESSION : null;
|
||||
}
|
||||
|
||||
export function createMockSessionCookie() {
|
||||
return {
|
||||
name: MOCK_SESSION_COOKIE_NAME,
|
||||
value: MOCK_SESSION_COOKIE_VALUE,
|
||||
httpOnly: true,
|
||||
sameSite: "lax" as const,
|
||||
secure: true,
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 7,
|
||||
};
|
||||
}
|
||||
|
||||
export function createClearedMockSessionCookie() {
|
||||
return {
|
||||
name: MOCK_SESSION_COOKIE_NAME,
|
||||
value: "",
|
||||
path: "/",
|
||||
maxAge: 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user