Authorization code example
const refreshTokens = await db.RefreshToken.find({ user: user.id });
req.user.ownsToken = token => !!refreshTokens.find(x => x.token === token);
next();
What does !! actually, do?
Authorization code example
const refreshTokens = await db.RefreshToken.find({ user: user.id });
req.user.ownsToken = token => !!refreshTokens.find(x => x.token === token);
next();
What does !! actually, do?
Any value can be converted to a real Boolean value using a double-negative
!! to be absolutely certain a false is generated only by false, 0, "", null, undefined and NaN:
// instead of
if (x === y) // ...
// runs if x and y are identical...
// except when both are NaN
// use
if (!!x === !!y) // ...
// runs if x and y are identical...
// including when either or both are NaN