API-Authentication-NodeJs
API-Authentication-NodeJs copied to clipboard
Why you used client.SET in this module? What is the Used
signRefreshToken: (userId) => { return new Promise((resolve, reject) => { const payload = {} const secret = process.env.REFRESH_TOKEN_SECRET const options = { expiresIn: '1y', issuer: 'pickurpage.com', audience: userId, } JWT.sign(payload, secret, options, (err, token) => { if (err) { console.log(err.message) // reject(err) reject(createError.InternalServerError()) }
client.SET(userId, token, 'EX', 365 * 24 * 60 * 60, (err, reply) => {
if (err) {
console.log(err.message)
reject(createError.InternalServerError())
return
}
resolve(token)
})
})
})
},
In summary, this code is setting a key-value pair in Redis where the key is the userId and the value is the token, with a time to live of 365 days, and it returns a promise to handle the success or failure of the operation.