Add the Workshops page and keep each sign-up on the site.
The form is built once to the settled field set, and a valid send is saved before anyone is emailed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
974a5ace4c
commit
c0ba3a3798
50 files changed
+2773
-1
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { sha256Hex } from "./hash";
|
||||
|
||||
export const WORKSHOP_INQUIRY_ADMIN_COOKIE = "workshop_inquiry_admin";
|
||||
|
||||
export function workshopInquiryAdminToken(): string | null {
|
||||
const raw = process.env.WORKSHOP_INQUIRY_ADMIN_TOKEN?.trim();
|
||||
return raw && raw.length > 0 ? raw : null;
|
||||
}
|
||||
|
||||
export function workshopInquiryPurgeToken(): string | null {
|
||||
const raw = process.env.WORKSHOP_INQUIRY_PURGE_TOKEN?.trim();
|
||||
return raw && raw.length > 0 ? raw : null;
|
||||
}
|
||||
|
||||
function cookieValue(token: string): string {
|
||||
return sha256Hex(`workshop-inquiry-admin:${token}`);
|
||||
}
|
||||
|
||||
export async function isWorkshopInquiryAdmin(): Promise<boolean> {
|
||||
const token = workshopInquiryAdminToken();
|
||||
if (!token) return false;
|
||||
const store = await cookies();
|
||||
return store.get(WORKSHOP_INQUIRY_ADMIN_COOKIE)?.value === cookieValue(token);
|
||||
}
|
||||
|
||||
export async function grantWorkshopInquiryAdmin(password: string): Promise<boolean> {
|
||||
const token = workshopInquiryAdminToken();
|
||||
if (!token || password !== token) return false;
|
||||
const store = await cookies();
|
||||
store.set(WORKSHOP_INQUIRY_ADMIN_COOKIE, cookieValue(token), {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 12,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user