Closed SwhiteMHC closed 3 months ago
Possible source of issue:
It seems initializePushNotifications() is ultimately calling await fetchAuthSession() from @aws-amplify/core. This call is failing as no user's are currently logged in. I am using the Amplify UI Authenticator for React Native, which is loaded to log the user in AFTER initializePushNotifications() has already been called....
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { Amplify } from 'aws-amplify';
import { initializePushNotifications } from 'aws-amplify/push-notifications';
import amplifyconfig from './src/amplifyconfiguration.json';
Amplify.configure(amplifyconfig);
initializePushNotifications();
AppRegistry.registerComponent(appName, () => App);
My configuration is similar (App.js).
import React from 'react';
// AWS
import {Authenticator} from '@aws-amplify/ui-react-native';
import {Amplify} from 'aws-amplify';
import {initializePushNotifications} from 'aws-amplify/push-notifications';
// Components
import AuthenticationGateway from './src/components/AuthenticationGateway/AuthenticationGateway';
// SplashScreen
import * as SplashScreen from 'expo-splash-screen';
SplashScreen.preventAutoHideAsync();
setTimeout(SplashScreen.hideAsync, 5000);
Amplify.configure({
Auth: {
Cognito: {
// Amazon Cognito User Pool ID
userPoolId: 'XXXX',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolClientId: 'XXXX',
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XXXX',
},
},
Notifications: {
PushNotification: {
Pinpoint: {
appId: 'XXXX',
region: 'us-west-2',
},
},
},
Analytics: {
Pinpoint: {
appId: 'XXXX',
region: 'us-west-2',
},
},
});
initializePushNotifications();
function App() {
return (
<Authenticator.Provider>
<AuthenticationGateway />
</Authenticator.Provider>
);
}
export default App;
Hello, @SwhiteMHC and thanks for opening this issue. To your point that initializePushNotifications()
calls fetchAuthSession()
under the hood, can you confirm if you have guest access (i.e. unauth roles) enabled for you app?
The invocation order was the problem. I needed to reorganize my code to ensure initializePushNotifications() was fired within my AuthenticationGateway component.
You can feel free to close. Thank you.
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, Analytics, Push Notifications
Amplify Version
v6
Amplify Categories
auth, analytics, notifications
Backend
Amplify CLI
Environment information
Describe the bug
Devices fail to register their token with Amazon Pinpoint.
Expected behavior
Devices successfully register with Amazon Pinpoint, allowing for push notifications to be sent to the device.
Reproduction steps
N/A
Code Snippet
Log output
aws-exports.js
Manual configuration
Additional configuration
Mobile Device
iPhone SE 2020
Mobile Operating System
iOS 17.2
Mobile Browser
N/A
Mobile Browser Version
N/A
Additional information and screenshots