Skip to content

Commit

Permalink
[#130] Fix web push notification not show in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Nov 6, 2024
1 parent 3d6a863 commit e6864db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion backend/core/socketio_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,17 @@ async def client_to_user(body: str):
)
for subscription in subscriptions:
try:
if (
"updates.push.services.mozilla.com"
in subscription.endpoint
):
VAPID_CLAIMS.update(
{"aud": "https://updates.push.services.mozilla.com"}
)
elif "fcm.googleapis.com" in subscription.endpoint:
VAPID_CLAIMS.update({"aud": "https://fcm.googleapis.com"})
else:
VAPID_CLAIMS.update({"aud": ""})
webpush(
subscription_info={
"endpoint": subscription.endpoint,
Expand All @@ -651,7 +662,10 @@ async def client_to_user(body: str):
session.delete(subscription)
session.commit()
else:
logger.error("Failed to send notification:", e)
logger.error(
f"Failed to send notification {subscription.endpoint}:",
e,
)
# EOL send push notification

logger.info(
Expand Down
2 changes: 1 addition & 1 deletion backend/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

VAPID_PRIVATE_KEY = os.getenv("NEXT_PUBLIC_VAPID_PRIVATE_KEY")
VAPID_PUBLIC_KEY = os.getenv("NEXT_PUBLIC_VAPID_PUBLIC_KEY")
VAPID_CLAIMS = {"sub": "mailto:[email protected]"}
VAPID_CLAIMS = {"sub": "mailto:[email protected]", "aud": ""}


class Subscription(SQLModel, table=True):
Expand Down
8 changes: 8 additions & 0 deletions backend/routes/subscription_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ async def send_notification(session: Session = Depends(get_session)):
subscriptions = session.exec(select(Subscription)).all()
for subscription in subscriptions:
try:
if "updates.push.services.mozilla.com" in subscription.endpoint:
VAPID_CLAIMS.update(
{"aud": "https://updates.push.services.mozilla.com"}
)
elif "fcm.googleapis.com" in subscription.endpoint:
VAPID_CLAIMS.update({"aud": "https://fcm.googleapis.com"})
else:
VAPID_CLAIMS.update({"aud": ""})
webpush(
subscription_info={
"endpoint": subscription.endpoint,
Expand Down

0 comments on commit e6864db

Please sign in to comment.