Skip to content

Commit 50891c6

Browse files
committed
chore(pronto): relax create-token constraints
1 parent 3b9a94a commit 50891c6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

sample-apps/react/react-dogfood/pages/api/auth/create-token.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NextApiRequest, NextApiResponse } from 'next';
22
import { createToken, maxTokenValidityInSeconds } from '../../../helpers/jwt';
33
import { getEnvironmentConfig } from '../../../lib/environmentConfig';
4+
import { getRandomName, sanitizeUserId } from '../../../lib/names';
45

56
export type CreateJwtTokenErrorResponse = {
67
error: string;
@@ -14,7 +15,7 @@ export type CreateJwtTokenResponse = {
1415
};
1516

1617
export type CreateJwtTokenRequest = {
17-
user_id: string;
18+
user_id?: string;
1819
environment?: string;
1920
/** @deprecated */
2021
api_key?: string;
@@ -26,7 +27,7 @@ const createJwtToken = async (
2627
res: NextApiResponse<CreateJwtTokenResponse | CreateJwtTokenErrorResponse>,
2728
) => {
2829
const {
29-
user_id: userId,
30+
user_id: userId = sanitizeUserId(getRandomName()),
3031
api_key: apiKeyFromRequest,
3132
...params
3233
} = req.query as CreateJwtTokenRequest;
@@ -40,10 +41,6 @@ const createJwtToken = async (
4041
else if (apiKeyFromRequest === '2g3htdemzwhg') environment = 'demo-flutter';
4142
}
4243

43-
if (!userId) {
44-
return error(res, `'user_id' is a mandatory query parameter.`);
45-
}
46-
4744
if (!params.exp) {
4845
params.exp = String(maxTokenValidityInSeconds);
4946
}

0 commit comments

Comments
 (0)