-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications.PushNotification - Failed to register device for push notifications #13494
Comments
@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 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 |
This doesn't work. When calling import * as PushNotification from 'aws-amplify/push-notifications';
...
await PushNotification.identifyUser({
userId: '',
userProfile: {},
options: { address: deviceToken.token, optOut: 'ALL' },
});
This is because |
Please see this ticket: 13504 |
@julian-dotcom There are two options here,
identifyUser({
userId: 'user-id-01',
userProfile: {name: 'user-test-name'},
options: {optOut: 'ALL'},
})
|
I created a patch, because in my estimation this is a bug. As I commented somewhere else: I investigated some more and figured out, what goes wrong. To me, it looks like a bug. When calling initializePushNotifications() in my index.js, the function calls addNativeListeners(), which calls addTokenEventListener(), which calls registerDevice(). The problem is that the register device function fails until a user is authenticated. This is fine and makes sense. However, the issue is that the exception is not passed on to initializePushNotifications(). This function continues and calls initialize(), setting initialized to true. This incorrect behavior because the device was never successfully registered, but the code now thinks it's initialized. Hence, whenever calling initializePushNotifications() after, the code just exits the function early and nothing happens. In my estimation, this should not happen. We should set initialized to true, ONLY if the device was successfully registered.
Source: |
Hi julian, what is the patch that you created?, I have the same error, I tried with workarounds that passed here but no success 😬 |
I'm also facing this issue and had some problems patching it. 😢 |
I created a patch for this file: I modify the
And I add
This is the actual patch file
|
thanks so much @julian-dotcom , it worked |
I have "aws-amplify": "^6.3.6" on my package.json.
|
@julian-dotcom @cwomack Is there a PR for this? |
@julian-dotcom @cwomack I also have the same issue. The patch does fix this issue. However, for some reason, I am not getting device token so the OptOut is set to "ALL". I also noticed that the token in the addTokenEventListener is undefined as well. |
I think this issue would be resolved if #13277 was resolved. |
@julian-dotcom, want to confirm something on how you're implementing the patch recommended in this comment above. Are you calling Currently, our documentation for implementing and initializing push notifications implies that the authenticated & unauthenticated with guest access enabled are supported. So this use case of unauthenticated users with guest access disabled for the identityPool is a bit of an edge case. |
When will the patch be merged and released? |
@georgeplaton7, we don't have a PR for this specifically yet I believe. The workaround/patch that's been mentioned was in @julian-dotcom's comment above (here) that others have reported working for them. We'd welcome anyone to submit a PR tied to this if they're willing, but since this is a bit of an edge case at this point for the use case of unauthenticated users with guest access being disabled for the identityPool. |
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
The text was updated successfully, but these errors were encountered: