mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
use seconds instead of ms for claims payload
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user