-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(packages/graphql): add script to impersonate student user
- Loading branch information
1 parent
ec835f8
commit 4954936
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { PrismaClient, UserRole } from '@klicker-uzh/prisma' | ||
import JWT from 'jsonwebtoken' | ||
import readline from 'readline' | ||
|
||
async function run(username: string) { | ||
const prisma = new PrismaClient() | ||
|
||
const participant = await prisma.participant.findUnique({ | ||
where: { | ||
username, | ||
}, | ||
}) | ||
|
||
if (!participant) { | ||
console.error('User not found') | ||
return | ||
} | ||
|
||
const jwt = JWT.sign( | ||
{ | ||
sub: participant.id, | ||
role: UserRole.PARTICIPANT, | ||
}, | ||
process.env.APP_SECRET as string, | ||
{ | ||
algorithm: 'HS256', | ||
expiresIn: '4w', | ||
} | ||
) | ||
|
||
console.log(jwt) | ||
} | ||
|
||
const readLine = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}) | ||
|
||
readLine.question( | ||
'Username of participant to impersonate:', | ||
async (username: string) => { | ||
await run(username) | ||
readLine.close() | ||
} | ||
) |