Skip to content

Commit

Permalink
chore(packages/graphql): add script to impersonate student user
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach committed Feb 21, 2025
1 parent ec835f8 commit 4954936
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/graphql/src/scripts/impersonateParticipant.ts
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()
}
)

0 comments on commit 4954936

Please sign in to comment.