Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions scripts/generate-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// scripts/generate-tokens.ts
import jwt from 'jsonwebtoken';
import crypto from 'crypto';
import { config } from 'dotenv';
import { DatabaseClient } from '../src/db';
import * as uuid from 'uuid';

config();

const db = new DatabaseClient();
const jwtSecret = process.env.JWT_SECRET!;

Expand All @@ -30,17 +33,27 @@ async function generateToken() {

// Generate and store refresh token for admin
const rawRefresh = crypto.randomBytes(32).toString('hex');
const analystRefresh = crypto.randomBytes(32).toString('hex');
const tokenHash = crypto.createHash('sha256').update(rawRefresh).digest('hex');
const analystTokenHash = crypto.createHash('sha256').update(analystRefresh).digest('hex');
await db.createSession({
id: uuid.v7(),
user_id: admin?.id ?? '8889143d-9063-4994-a622-2b857591b3c4',
token_hash: tokenHash,
expires_at: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
});

await db.createSession({
id: uuid.v7(),
user_id: analyst?.id ?? 'bcdc0edd-4a48-440d-96c7-b54289410c85',
token_hash: analystTokenHash,
expires_at: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
});

console.log('Admin token:', adminToken);
console.log('Analyst token:', analystToken);
console.log('Refresh token (admin):', rawRefresh);
console.log('Refresh token (analyst): ', analystRefresh);
}

generateToken().catch((err) => {
Expand Down
Loading