Skip to content

Commit

Permalink
Change approach to fix validation error of protocol not beeing returned
Browse files Browse the repository at this point in the history
Fixes #830

Change the solution based on the review
  • Loading branch information
glasgio authored Aug 31, 2023
1 parent a630d81 commit d11c300
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/vapid-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ function validateSubject(subject) {

try {
const subjectParseResult = new URL(subject);
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
}
if (subjectParseResult.hostname === 'localhost') {
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
+ 'sending notifications.');
}
} catch (err) {
throw new Error('Vapid subject is not a valid URL. ' + subject, { cause: err });
throw new Error('Vapid subject is not a valid URL. ' + subject);
}
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
}
if (subjectParseResult.hostname === 'localhost') {
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
+ 'sending notifications.');
}

function validatePublicKey(publicKey) {
Expand Down

0 comments on commit d11c300

Please sign in to comment.