Skip to content

Commit 91b4e14

Browse files
gavrashenkomarco-c
andauthored
Remove useless second subscription.keys validation (#549)
Co-authored-by: Marco Castelluccio <[email protected]>
1 parent 02121d5 commit 91b4e14

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/web-push-lib.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ WebPushLib.prototype.generateRequestDetails = function(subscription, payload, op
9696

9797
if (payload) {
9898
// Validate the subscription keys
99-
if (!subscription.keys || !subscription.keys.p256dh
99+
if (typeof subscription !== 'object' || !subscription.keys
100+
|| !subscription.keys.p256dh
100101
|| !subscription.keys.auth) {
101102
throw new Error('To send a message with a payload, the '
102103
+ 'subscription must have \'auth\' and \'p256dh\' keys.');
@@ -208,15 +209,6 @@ WebPushLib.prototype.generateRequestDetails = function(subscription, payload, op
208209
let requestPayload = null;
209210

210211
if (payload) {
211-
if (!subscription.keys
212-
|| typeof subscription !== 'object'
213-
|| !subscription.keys.p256dh
214-
+ !subscription.keys.auth) {
215-
throw new Error(new Error('Unable to send a message with '
216-
+ 'payload to this subscription since it doesn\'t have the '
217-
+ 'required encryption keys'));
218-
}
219-
220212
const encrypted = encryptionHelper
221213
.encrypt(subscription.keys.p256dh, subscription.keys.auth, payload, contentEncoding);
222214

0 commit comments

Comments
 (0)