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,25 +109,30 @@ export class NotificationService {
"apns-priority": "10",
"apns-topic": bundleId,
};
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify({
aps: {
alert: {
title: "Shuttle is arriving",
body: `Shuttle is approaching ${stop.name} in ${Math.ceil(eta.secondsRemaining / 60)} minutes.`
try {
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify({
aps: {
alert: {
title: "Shuttle is arriving",
body: `Shuttle is approaching ${stop.name} in ${Math.ceil(eta.secondsRemaining / 60)} minutes.`
}
}
}
}),
});
const json = await response.json();
}),
});
const json = await response.json();
if (response.status !== 200) {
console.error(`Notification failed for device ${deviceId}:`, json.reason);
if (response.status !== 200) {
console.error(`Notification failed for device ${deviceId}:`, json.reason);
return false;
}
return true;
} catch(e) {
console.error(e);
return false;
}
return true;
}
public static getAPNsFullUrlToUse(deviceId: string) {