Next.js app with a browser-side buttplug/buttplug-wasm control layer (server never touches real-time device commands), SQLite storage via Drizzle, single-secret auth, recordings/replay with device remapping, a usage stats dashboard, Docker deployment, and Gitea CI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W8WkFF5ppURBAB918593Eb
38 lines
948 B
TypeScript
38 lines
948 B
TypeScript
import { SignJWT, jwtVerify } from "jose";
|
|
import { getEnv } from "@/lib/env";
|
|
|
|
export const SESSION_COOKIE_NAME = "bp_session";
|
|
const SESSION_MAX_AGE_SECONDS = 60 * 60 * 24 * 30; // 30 days
|
|
|
|
function signingKey(): Uint8Array {
|
|
return new TextEncoder().encode(getEnv().AUTH_SECRET);
|
|
}
|
|
|
|
export async function createSessionToken(): Promise<string> {
|
|
return new SignJWT({})
|
|
.setProtectedHeader({ alg: "HS256" })
|
|
.setSubject("app")
|
|
.setIssuedAt()
|
|
.setExpirationTime(`${SESSION_MAX_AGE_SECONDS}s`)
|
|
.sign(signingKey());
|
|
}
|
|
|
|
export async function verifySessionToken(token: string | undefined | null): Promise<boolean> {
|
|
if (!token) return false;
|
|
try {
|
|
await jwtVerify(token, signingKey());
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export const sessionCookieOptions = {
|
|
name: SESSION_COOKIE_NAME,
|
|
httpOnly: true,
|
|
secure: true,
|
|
sameSite: "lax" as const,
|
|
path: "/",
|
|
maxAge: SESSION_MAX_AGE_SECONDS,
|
|
};
|