refreshToken
is a string that is checked to see if it is in line with encoding.
currentHashedRefreshToken
is currently an encoded token.
isRefreshTokenMatching
is a boolean variable that compares if the encoded string matches bcrypt.
{
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiOWRiMTcwMmMtNDkyYy00MTJmLTkyM2QtM2Y5MWQyYzk0NTNjIiwicm9sZSI6IkNVU1RPTUVSX1JPTEUiLCJpYXQiOjE2MDU0NzM4NTcsImV4cCI6MTYwNTQ3NzQ1N30.o9nEeH4V7PZ61jWRG7-7epH79Vi9HJQWorvx5A37q4o'
}
{
currentHashedRefreshToken: '$2b$10$ZYsrh1xu3icprkvRI0OksuBx6hrfOs9lmO7oZ2qqM6pFCLDiVaQrq'
}
{ isRefreshTokenMatching: true }
secound:
{
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiOWRiMTcwMmMtNDkyYy00MTJmLTkyM2QtM2Y5MWQyYzk0NTNjIiwicm9sZSI6IkNVU1RPTUVSX1JPTEUiLCJpYXQiOjE2MDU0NzUzOTgsImV4cCI6MTYwNTQ3ODk5OH0.iHRhFmtgRbsgTv9uC7VDaT_bU1tHxdlCjHDCjfmxeKA'
}
{
currentHashedRefreshToken: '$2b$10$ZYsrh1xu3icprkvRI0OksuBx6hrfOs9lmO7oZ2qqM6pFCLDiVaQrq'
}
{ isRefreshTokenMatching: true }
why both refresh tokens detect that they match if they are different and different?
Here are my methods for hashing and decoding:
/**
* generate hash from password or string
* @param {string} password
* @returns {Promise<string>}
*/
static async generateHash(password: string): Promise<string> {
return bcrypt.hash(password, 10);
}
/**
* validate text with hash
* @param {string} password
* @param {string} hash
* @returns {Promise<boolean>}
*/
static async validateHash(password: string, hash?: string): Promise<boolean> {
return bcrypt.compare(password, hash || '');
}