Closed Mehrdadgame closed 1 year ago
@Mehrdadgame The JavaScript runtime in the game server is not a Node runtime; it is also sandboxed for performance and security reasons. We already provide a jwtGenerate
function in the server framework you can use to generate the token structure you need:
Hope this helps.
Hi I working with Nakama typescript I want use jsonwebtoken for login custom but i have error in Tsconfig.json and change "module": "System" in tsconfig and add let jws= require('jsonwebtoken'); error on start server . Failed initializing runtime modules","error":"ReferenceError: require is not defined at index.js:84:18(54)
Description
Tsconfig.json :
"compilerOptions": { "target": "ES5", "module": "System", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "outFile": "./modules/index.js", "typeRoots": [ "./node_modules" , "./node_modules/@types" ] }
Expected Result
const verifyAndParseJwt = function (secretKey: string, jwtt: string , logger:nkruntime.Logger): Claims { let claims: Claims={id:"", username:""}; // Use your favourite JWT library to verify the signature and decode the JWT contents
jws.sign({ foo: jwtt }, secretKey, { algorithm: 'RS256' }, function(err:any, token:any) { logger.info(token + " %%%%%%%%%%%%%%%%%%%%%%"); claims.id=token.id; claims.username = token.username; });
Context