tattle-made / kosh-v2

3 stars 4 forks source link

#12 | GP | Added. Table, APIs, Screens for create, read, delete acces… #39

Closed gpstrange closed 2 years ago

dennyabrain commented 2 years ago

@gpstrange discovered a minor bug. When i press the "copy to clipboard" button, it seems to always copy the same jwt token in the clipboard.

dennyabrain commented 2 years ago

this might be the root cause of the problem. If we create a token by calling jwt.sign with the same data, it will always generate the same token.

lets try to pass the id of the access token as one of the parameters to jwt.sign for instance,

// the build function only creates an instance of the model but does not save it to db
let newAccessToken = accessToken.build({ userId: request.user.id });
const accessToken = jwt.sign(
    {
        ...request.user,
        token : newAccessToken.id
    },
    process.env.ACCESS_TOKEN_SECRET,
)
// this will actually write to the database
await newAccessToken.save() 

This is untested Code. you might have to add other mandatory fields to the accessToken object before saving to db, but i hope you got the idea.