I have some node.js Azure Functions (httptriggers) coded with Typescript that I secure with a jwt token. After validating my token at the beginning of the funtion, I'd like to store it globally so I can use it in all my child functions. But I'd like my token to be valid only for the current Invokation Context. I don't want to pass the token as parameter to any function that may need it.
Example:
// I'd like to store it like that, but that isn't thread safe, other user may get the same tokenexport let globalToken : any;export async function users(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> { globalToken = validateToken(request); if(request.method === "GET"){ return { jsonBody: getUsers() }; }}//### In user.service.ts file ###export const getUsers = () => { // so I can use it everywhere like that, without passing it in parameter every time return usersData.filter(u => u.userId === globalToken.userId)}
Any suggestions?