Giter VIP home page Giter VIP logo

Comments (10)

villarama37 avatar villarama37 commented on May 20, 2024 9

I think I figured it out. It assumes that your App inherits from AuthPiece (https://github.com/aws-amplify/amplify-js/blob/master/packages/aws-amplify-react/src/Auth/AuthPiece.jsx).

import { Authenticator, AuthPiece } from 'aws-amplify-react';

class App extends AuthPiece {
  constructor(props) {
    super(props);
    this._validAuthStates = ['signedIn'];
  }

  showComponent(theme) {
    return (
      <div className="App">
      </div>
    );
  }
}

class AppWithAuthenticator extends React.Component {
  render() {
    return (
      <Authenticator >
        <App />
      </Authenticator>
    );
  }
}

export default AppWithAuthenticator;
}

from docs.

amirmishani avatar amirmishani commented on May 20, 2024 5

Yeah it's not clear. If you're just looking to render your own component (let's say <App/>) after a successful login then it's simple and you can do something like this:

import React, { Component } from 'react';
import { Authenticator } from 'aws-amplify-react';
import awsConfig from './aws-exports';
import App from './App';

class AppWithAuth extends Component {
  state = {
    authState: ''
  };

  render() {
    return (
      <div>
        <Authenticator
          amplifyConfig={awsConfig}
          onStateChange={authState => this.setState({ authState })}
        >
          {this.state.authState === 'signedIn' && <App />}
        </Authenticator>
      </div>
    );
  }
}

export default AppWithAuth;

Remember that authData will be passed to your <App/> with all of your Cognito user object and you can use it inside your App component for example props.authData.attributes will contain all of your user info.

One more thing, you don't need amplifyConfig prop if you've already setup Amplify.configure(awsConfig) per Amplify docs.

from docs.

EliotSlevin avatar EliotSlevin commented on May 20, 2024 1

Still finding this very confusing. I'm also confused why withAuthenticator can't pass down the full list of props to the Authenticator component it creates itself. All I need to do is hide signup, and setting up a full Authenticator implementation just to do that feels like a lot of work - when there's already hideGreetings

from docs.

alenpesikan avatar alenpesikan commented on May 20, 2024

This works only with default Authenticator. If hideDefault is set to true, it throws error in the Authenticator component : Cannot read property 'override' of undefined

from docs.

stale avatar stale commented on May 20, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from docs.

stale avatar stale commented on May 20, 2024

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

from docs.

azatoth avatar azatoth commented on May 20, 2024

This is still an issue; Do I have to create a new ticket for this, as it's been marked stale?

from docs.

 avatar commented on May 20, 2024

Does anyone know how to do it with functional component? It's been 2 years now but documentation is still confusing.

from docs.

dnishiyama avatar dnishiyama commented on May 20, 2024

@tonydatw did you ever find an answer on this? I'm trying with a functional component and also struggling

from docs.

 avatar commented on May 20, 2024

@tonydatw did you ever find an answer on this? I'm trying with a functional component and also struggling

Solved it by creating a login/signup screen flow, then wrapping it in the <Authenticator> </Authenticator> component and finally wrapping everything in a <NavigationContainer> </NavigationContainer> :

return (
     <NavigationContainer >
      <Authenticator  authState="signIn">
        <StatusBar/>
        <AuthScreens/>
      </Authenticator>
     </NavigationContainer>
  )

You can assign props "signedIn" to the screen that you want rendered after successfull login/signup, in AuthScreens.

from docs.

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.