41 lines
976 B
TypeScript
41 lines
976 B
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import crypto from 'crypto';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
function token() {
|
|
return crypto.randomBytes(24).toString('hex');
|
|
}
|
|
function futureHours(h:number) {
|
|
const d = new Date();
|
|
d.setHours(d.getHours() + h);
|
|
return d;
|
|
}
|
|
|
|
async function main() {
|
|
const users = await prisma.users.findMany({ select: { id: true } });
|
|
let created = 0;
|
|
|
|
for (const u of users) {
|
|
await prisma.oAuthSessions.create({
|
|
data: {
|
|
user_id: u.id,
|
|
application: 'targo-2.0',
|
|
access_token: token(),
|
|
refresh_token: token(),
|
|
sid: token(),
|
|
access_token_expiry: futureHours(2),
|
|
refresh_token_expiry: futureHours(24 * 30),
|
|
is_revoked: false,
|
|
scopes: [],
|
|
},
|
|
});
|
|
created++;
|
|
}
|
|
|
|
const total = await prisma.oAuthSessions.count();
|
|
console.log(`✓ OAuthSessions: ${total} total (added ${created})`);
|
|
}
|
|
|
|
main().finally(() => prisma.$disconnect());
|