You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checar chave ‘environment’ dentro do arquivo .YAML (usado para criar o Docker)
se existe o campo JWT_SECRET ou similar onde estará a chave secreta.
criar diretório 'Util' em 'src'
criar arquivo 'jwt.js' em 'Util'
conteúdo: (função de criação do token)
importdotenvfrom'dotenv';constjwt=require('jsonwebtoken');constTOKEN_SECRET_KEY=process.env.JWT_SECRET;constgenerateToken=(data)=>{constpayload={
...data,};constjwtConfig={expiresIn: '50m',// tempo até expirar o token (ex 15d – 15 dias)algorithm: 'HS256',};consttoken=jwt.sign(payload,TOKEN_SECRET_KEY,jwtConfig);returntoken;};constauthenticateToken=async(token)=>{if(!token){conststatus=401;constmessage='Token not found';return{ status, message };}try{constvalidateToken=jwt.verify(token,TOKEN_SECRET_KEY);console.log(validateToken);returnvalidateToken;}catch(error){conststatus=401;constmessage='Expired or invalid token';return{ status, message };}};module.exports={
generateToken,
authenticateToken,};