17 lines
548 B
TypeScript
17 lines
548 B
TypeScript
import { initializeDatabase, pool } from "./db.js";
|
|
import { createId, createSecret, hashSecret, INVITATION_TTL_MS } from "./security.js";
|
|
|
|
await initializeDatabase();
|
|
|
|
const key = createSecret();
|
|
const expiresAt = new Date(Date.now() + INVITATION_TTL_MS);
|
|
await pool.query(
|
|
`INSERT INTO app_invitations (id, key_hash, expires_at)
|
|
VALUES ($1, $2, $3)`,
|
|
[createId(), hashSecret(key), expiresAt],
|
|
);
|
|
|
|
const origin = process.env.PUBLIC_ORIGIN ?? "http://localhost:5173";
|
|
process.stdout.write(`${origin}/invite?key=${key}\n`);
|
|
await pool.end();
|