API-Authentication-NodeJs icon indicating copy to clipboard operation
API-Authentication-NodeJs copied to clipboard

Why you used client.SET in this module? What is the Used

Open amitjoshi22 opened this issue 3 years ago • 1 comments

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)
    })
  })
})

},

amitjoshi22 avatar Jul 07 '22 11:07 amitjoshi22

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.

Ameprizzo avatar Jan 25 '23 08:01 Ameprizzo