Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
fix push subscription check erroring when unregistered
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialCrafter committed Jan 23, 2024
1 parent ab3885b commit 8d422d4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/push.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const sendNotification = async (data, user) => {
setVapidDetails();
// eslint-disable-next-line no-param-reassign
if (typeof user === 'string') user = await User.findById(user);
if (!user.pushSubscription) return;
if (!user?.pushSubscription) return;

const { pushSubscription } = user;
return webpush.sendNotification(
Expand Down
2 changes: 1 addition & 1 deletion src/routes/dashboard/notifications/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const actions = {
const data = jwt.verify(token, JWT_SECRET);
const user = await User.findOne({ _id: data._id });

if (!user.pushSubscription) throw error(400, 'Unregistered');
if (!user?.pushSubscription) throw error(400, 'Unregistered');
const { pushSubscription } = user;

await webpush
Expand Down

0 comments on commit 8d422d4

Please sign in to comment.