feat: Finish push token registration with backend - #873
Open
dominiccreates wants to merge 2 commits into
Open
Conversation
|
@dominiccreates Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #745
This PR completes the push notification token registration flow by syncing Expo tokens from the mobile app with the backend. It also ensures tokens are reliably refreshed and cleanly revoked upon user sign-out, while also surfacing sync errors in the mobile app settings.
Changes Made
Frontend (Mobile):
New Service: Added deviceTokenApi.ts to manage syncing with the backend /device-tokens and /device-tokens/revoke-by-token endpoints. It automatically attaches the wallet publicKey via the x-user-id header for authentication.
Auto-Sync: Updated NotificationContext.tsx to automatically call syncToken whenever push notification permissions are granted and a new Expo push token is acquired.
Sign-Out Flow: Updated WalletContext.tsx to automatically call revokeToken when a user disconnects their wallet, ensuring the token is invalidated on the backend.
Error Visibility: Updated SettingsScreen.tsx to render a visible error banner beneath the notifications section if a token fails to sync with the backend.
Backend:
New Endpoint: Added a POST /device-tokens/revoke-by-token endpoint for mobile clients to easily revoke tokens without needing the internal database ID.
Mobile Auth: Added the @public() decorator to /device-tokens routes to bypass strict API key enforcement, and updated the controller to accept the user's wallet public key via the x-user-id header when identifying the actor.
Testing/Verification
Registration: Open the mobile app and grant push notification permissions. Verify that a new record is created in the backend DeviceNotificationToken table containing the wallet publicKey as the userId.
Sign-Out: Disconnect the wallet in the app. Verify that the token record is marked as revoked (isActive: false and revokedAt is populated) in the database.
Error Handling: Simulate a network failure or backend error and verify that the red sync error banner appears on the Settings screen.
1:04 PM