Open julian-dotcom opened 2 weeks ago
@julian-dotcom Thank you for your report! It seems like the application is having trouble when users are unauthenticated. Could you confirm that you've enabled unauthenticated access when setting up your backend? Reference: https://docs.amplify.aws/gen1/react-native/build-a-backend/push-notifications/set-up-push-notifications/#set-up-backend-resources
We only want to send notifications to authenticated users. We never want unauthenticated users to receive notifications.
But as far as I understand initializePushNotifications()
has to be called in the index.js.
How do I prevent it from registering the device for push notifications until the user logs in?
@julian-dotcom Unfortunately this is a use-case that we don't directly support at the moment. However, there is a possible work around you can try: Using identifyUser
to mark or unmark a particular device, for example setting optOut: 'ALL'
until the user is signed in and resetting it when they sign out.
This doesn't work. When calling identifyUser
like so:
import * as PushNotification from 'aws-amplify/push-notifications';
...
await PushNotification.identifyUser({
userId: '',
userProfile: {},
options: { address: deviceToken.token, optOut: 'ALL' },
});
identifyUser
never finishes executing.
This is because const { credentials, identityId } = await resolveCredentials();
fails in line 28 of node_modules/@aws-amplify/notifications/src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts
Please see this ticket: 13504
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, Analytics, Push Notifications
Amplify Version
v6
Amplify Categories
auth, analytics, notifications
Backend
Other
Environment information
Describe the bug
When I launch my React Native app in an unauthenticated state, I get the following error:
[ERROR] 57:31.569 Notifications.PushNotification - Failed to register device for push notifications [NoCredentials: Credentials should not be empty.]
This happens when I call
initializePushNotifications()
in my index.js.When a user is authenticated and I launch the app, the error does NOT show up.
The error also doesn't show up if
initializePushNotifications()
is commented out.Expected behavior
Get no error when launching the app in its unauthenticated state.
Reproduction steps
npx react-native run-android
Code Snippet
This is the code for my index.js:
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response