mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
fix: ensure that number is whole (#2416)
This commit is contained in:
@@ -92,7 +92,11 @@ export async function handleLogout(redis: Redis, req: Request, res: Response) {
|
||||
const { jti, exp }: LogoutToken = validate(LogoutTokenSchema, decoded);
|
||||
if (jti && exp) {
|
||||
// Compute the number of seconds that the token will be valid for.
|
||||
const validFor = exp - now.valueOf() / 1000;
|
||||
const validFor = Math.round(
|
||||
DateTime.fromJSDate(now)
|
||||
.plus({ seconds: -exp })
|
||||
.toSeconds()
|
||||
);
|
||||
if (validFor > 0) {
|
||||
// Invalidate the token, the expiry is in the future and it needs to be
|
||||
// revoked.
|
||||
|
||||
@@ -3,6 +3,7 @@ import { IncomingMessage } from "http";
|
||||
import { Redis } from "ioredis";
|
||||
import Joi from "joi";
|
||||
import jwt, { SignOptions, VerifyOptions } from "jsonwebtoken";
|
||||
import { DateTime } from "luxon";
|
||||
import { Bearer, BearerOptions } from "permit";
|
||||
import uuid from "uuid/v4";
|
||||
|
||||
@@ -352,8 +353,8 @@ export async function revokeJWT(
|
||||
) {
|
||||
await redis.setex(
|
||||
generateJTIRevokedKey(jti),
|
||||
Math.ceil(validFor),
|
||||
now.valueOf()
|
||||
Math.round(validFor),
|
||||
Math.round(DateTime.fromJSDate(now).toSeconds())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function generateInviteURL(
|
||||
jti: uuid.v4(),
|
||||
iss: tenant.id,
|
||||
sub: id,
|
||||
exp: Math.floor(user.expiresAt.valueOf() / 1000),
|
||||
exp: Math.round(DateTime.fromJSDate(user.expiresAt).toSeconds()),
|
||||
iat: nowSeconds,
|
||||
nbf: nowSeconds,
|
||||
aud: "invite",
|
||||
|
||||
@@ -283,7 +283,7 @@ export async function createToken(
|
||||
issuer: tenant.id,
|
||||
|
||||
// Tokens are not valid before the creation date.
|
||||
notBefore: DateTime.fromJSDate(now).toSeconds(),
|
||||
notBefore: Math.round(DateTime.fromJSDate(now).toSeconds()),
|
||||
});
|
||||
|
||||
return { ...result, signedToken };
|
||||
|
||||
Reference in New Issue
Block a user