Skip to content

Commit

Permalink
fix #18: access token in the worker process has 1h expiry time
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk committed Feb 1, 2024
1 parent 7e74580 commit 3d9206f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apps/worker/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createJwt } from "@letsgo/trust";
import { VendorPrefix } from "@letsgo/constants";

const DefaultWorkerAccessTokenExpiry = 3600;
const DefaultWorkerAccessTokenExpirySeconds = 3600;
const RenewBeforeExpirySeconds = 60;
const WorkerSubject = `${VendorPrefix}:worker`;

Expand All @@ -16,12 +16,12 @@ let token: string = "";
export async function getAccessToken() {
if (renewAt < Date.now()) {
token = await createJwt({
expiresIn: `${DefaultWorkerAccessTokenExpiry}`,
expiresIn: `${DefaultWorkerAccessTokenExpirySeconds}s`,
subject: WorkerSubject,
});
renewAt =
Date.now() +
(DefaultWorkerAccessTokenExpiry - RenewBeforeExpirySeconds) * 1000;
(DefaultWorkerAccessTokenExpirySeconds - RenewBeforeExpirySeconds) * 1000;
}
return token;
}

0 comments on commit 3d9206f

Please sign in to comment.