server/src/api/controllers/auth.controller.js
/**
 * Gera ambos access e refresh token.
 * @param {string} id 
 * @param {string} username 
 * @returns {{
 *  access_token: {
 *      token: string,
 *      expires_in: number
 *  },
 *  refreesh_token: {
 *      token: string,
 *      expires_in: number
 *  },
 *  token_type: string
 * }}
 */
Gera ambos access e refresh token.
Gera ambos access e refresh token .
function generateTokens(id, username) {
    const accessTokenData = {
        id,
        username,
        access_token: true
    }
    const refreshTokenData = {
        id,
        username,
        access_token: false
    }
    const accessTokenExpiration  = 1800   
    const refreshTokenExpiration = 604800 
    const accessToken  = jwt.signAccess (accessTokenData,  accessTokenExpiration )
    const refreshToken = jwt.signRefresh(refreshTokenData, refreshTokenExpiration)
    return {
        access_token: {
            token: accessToken,
            expires_in: accessTokenExpiration
        },
        refresh_token: {
            token: refreshToken,
            expires_in: refreshTokenExpiration
        },
        token_type:   "Bearer"
    }
}
function generateTokens ( id , username ) { const accessTokenData = { id , username , access_token : true } const refreshTokenData = { id , username , access_token : false } const accessTokenExpiration = 1800 const refreshTokenExpiration = 604800 const accessToken = jwt . signAccess ( accessTokenData , accessTokenExpiration ) const refreshToken = jwt . signRefresh ( refreshTokenData , refreshTokenExpiration ) return { access_token : { token : accessToken , expires_in : accessTokenExpiration } , refresh_token : { token : refreshToken , expires_in : refreshTokenExpiration } , token_type : "Bearer" } }
Gera ambos access e refresh token.
Gera ambos access e refresh token .
// 30 minutos // 1 semana