init: init prok

This commit is contained in:
2026-04-16 15:34:47 +08:00
commit db74381f13
56 changed files with 5850 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import jwt from "jsonwebtoken";
const SECRET = process.env.JWT_SECRET || "dev-secret";
const EXPIRES_IN = "7d";
export function signToken(userId: string): string {
return jwt.sign({ sub: userId }, SECRET, { expiresIn: EXPIRES_IN });
}
export function verifyToken(token: string): { sub: string } | null {
try {
return jwt.verify(token, SECRET) as { sub: string };
} catch {
return null;
}
}

View File

@@ -0,0 +1,12 @@
import QRCode from "qrcode";
export async function generateQRCodeDataURL(
url: string,
options?: { width?: number }
): Promise<string> {
return QRCode.toDataURL(url, {
width: options?.width ?? 300,
margin: 2,
color: { dark: "#1a1a2e", light: "#ffffff" },
});
}