use seconds instead of ms for claims payload

This commit is contained in:
2025-02-10 10:32:46 -08:00
parent 7e764502a0
commit a6138b37cb

View File

@@ -54,17 +54,17 @@ export class NotificationService {
"kid": keyId,
};
const now = Date.now();
const nowMs = Date.now();
const claimsPayload = {
"iss": teamId,
"iat": now,
"iat": Math.ceil(nowMs / 1000), // APNs requires number of seconds since Epoch
};
this.apnsToken = jwt.sign(claimsPayload, privateKey, {
algorithm: "ES256",
header: tokenHeader
});
this._lastRefreshedTimeMs = now;
this._lastRefreshedTimeMs = nowMs;
}
private lastReloadedTimeForAPNsIsTooRecent() {
@@ -109,6 +109,7 @@ export class NotificationService {
"apns-priority": "10",
"apns-topic": bundleId,
};
try {
const response = await fetch(url, {
method: "POST",
headers,
@@ -128,6 +129,10 @@ export class NotificationService {
return false;
}
return true;
} catch(e) {
console.error(e);
return false;
}
}
public static getAPNsFullUrlToUse(deviceId: string) {