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