mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(jwt generation): Simplify payload property assignments and secret initialization
This commit is contained in:
parent
c3986d7a08
commit
f49a67f8df
@ -85,18 +85,23 @@ export function generateJwt(options: GenerateJWTOptions = {}): string {
|
|||||||
alg: "HS256",
|
alg: "HS256",
|
||||||
typ: "JWT",
|
typ: "JWT",
|
||||||
});
|
});
|
||||||
payload.iss || (payload.iss = "dokploy");
|
if (!payload.iss) {
|
||||||
payload.iat || (payload.iat = Math.floor(Date.now() / 1000));
|
payload.iss = "dokploy";
|
||||||
payload.exp ||
|
}
|
||||||
(payload.exp = Math.floor(
|
if (!payload.iat) {
|
||||||
new Date("2030-01-01T00:00:00Z").getTime() / 1000,
|
payload.iat = Math.floor(Date.now() / 1000);
|
||||||
));
|
}
|
||||||
|
if (!payload.exp) {
|
||||||
|
payload.exp = Math.floor(new Date("2030-01-01T00:00:00Z").getTime() / 1000);
|
||||||
|
}
|
||||||
const encodedPayload = objToJWTBase64({
|
const encodedPayload = objToJWTBase64({
|
||||||
iat: Math.floor(Date.now() / 1000),
|
iat: Math.floor(Date.now() / 1000),
|
||||||
exp: Math.floor(new Date("2030-01-01T00:00:00Z").getTime() / 1000),
|
exp: Math.floor(new Date("2030-01-01T00:00:00Z").getTime() / 1000),
|
||||||
...payload,
|
...payload,
|
||||||
});
|
});
|
||||||
secret || (secret = randomBytes(32).toString("hex"));
|
if (!secret) {
|
||||||
|
secret = randomBytes(32).toString("hex");
|
||||||
|
}
|
||||||
const signature = safeBase64(
|
const signature = safeBase64(
|
||||||
createHmac("SHA256", secret)
|
createHmac("SHA256", secret)
|
||||||
.update(`${encodedHeader}.${encodedPayload}`)
|
.update(`${encodedHeader}.${encodedPayload}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user