-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🩹 Fix the
dev:authtoken
script (#4622)
Fix the `dev:authtoken` script
- Loading branch information
Showing
4 changed files
with
26 additions
and
10 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
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
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
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
import readline from 'readline' | ||
|
||
import { createAuthToken } from '@/auth/model/token' | ||
import { prisma } from '@/common/prisma' | ||
import { APP_SECRET_KEY } from '@/common/config' | ||
|
||
const memberId = process.argv[2] ? Number(process.argv[2]) : 1 | ||
run() | ||
|
||
if (!prisma.member.findUnique({ where: { id: memberId } })) { | ||
process.stderr.write(`There is no member with the id ${memberId}\n`) | ||
} | ||
async function run() { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
terminal: false, | ||
}) | ||
|
||
const memberId: number = await new Promise((res) => rl.question('Member id [1]:', (a) => res((a && Number(a)) || 1))) | ||
const secret: string = await new Promise((res) => | ||
rl.question(`App secret key [${APP_SECRET_KEY}]:`, (a) => res(a || APP_SECRET_KEY)) | ||
) | ||
|
||
process.stdout.write(createAuthToken(Number(memberId)) + '\n') | ||
rl.close() | ||
|
||
const token = createAuthToken(Number(memberId), secret) + '\n' | ||
const httpHeaders = { Authorization: `Bearer ${token}` } | ||
|
||
process.stdout.write(JSON.stringify(httpHeaders, null, 2) + '\n') | ||
} |