Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): extract verified password cookie helper

Richie McIlroycc97031e5325
diff --git a/apps/web/lib/password-cookie.ts b/apps/web/lib/password-cookie.ts
new file mode 100644
index 000000000..138371047
--- /dev/null
+++ b/apps/web/lib/password-cookie.ts
@@ -0,0 +1,18 @@
+import "server-only";
+
+import { encrypt } from "@cap/database/crypto";
+import { cookies } from "next/headers";
+
+/**
+ * Marks a share password (video or collection) as verified for this browser
+ * session. The cookie is shared by the `/s/` and `/c/` flows, holds only the
+ * encrypted hash, and is never read client-side — so it can be locked down.
+ */
+export async function setVerifiedPasswordCookie(passwordHash: string) {
+ (await cookies()).set("x-cap-password", await encrypt(passwordHash), {
+ httpOnly: true,
+ secure: process.env.NODE_ENV === "production",
+ sameSite: "lax",
+ path: "/",
+ });
+}