File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed
sample-apps/react/react-dogfood/pages/api/auth Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change 11import { NextApiRequest , NextApiResponse } from 'next' ;
22import { createToken , maxTokenValidityInSeconds } from '../../../helpers/jwt' ;
33import { getEnvironmentConfig } from '../../../lib/environmentConfig' ;
4+ import { getRandomName , sanitizeUserId } from '../../../lib/names' ;
45
56export type CreateJwtTokenErrorResponse = {
67 error : string ;
@@ -14,7 +15,7 @@ export type CreateJwtTokenResponse = {
1415} ;
1516
1617export 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 }
You can’t perform that action at this time.
0 commit comments