Coder Social home page Coder Social logo

Comments (3)

SwhiteMHC avatar SwhiteMHC commented on May 20, 2024 2

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.

from amplify-js.

SwhiteMHC avatar SwhiteMHC commented on May 20, 2024

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;

from amplify-js.

cwomack avatar cwomack commented on May 20, 2024

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?

from amplify-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.