Comments (10)
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.
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.
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.
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.
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.
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.
from docs.
This is still an issue; Do I have to create a new ticket for this, as it's been marked stale?
from docs.
Does anyone know how to do it with functional component? It's been 2 years now but documentation is still confusing.
from docs.
@tonydatw did you ever find an answer on this? I'm trying with a functional component and also struggling
from docs.
@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)
- Backend deployment for mobile with Gen2 DX is not clear and points to NextJs guide
- Problem with NuxtJS SSR Docs HOT 4
- When two headings have the same name the anchor links always link to the first one
- [missing-page] HOT 1
- [missing-page] HOT 2
- Native TOTP docs showing extra JS page
- [missing-page] HOT 1
- Where can I find the sample of PubSub by Android? HOT 1
- [Gen 2] SSO setup has the same screenshot
- Enum Field with Same Name in Different Models
- Bad link on docs page
- Non-linear documentation
- ToDo Doc Issue at https://docs.amplify.aws/react/start/getting-started/auth/#create-login-ui
- Can't find the page. HOT 2
- Unclear how to make a secondary index on another model HOT 2
- The Quick Start Next.js App Router Start a local dev server is duplicated HOT 2
- [missing-page]
- flutter getting starting guide is missing amplify init instructions
- Missing documentation for `preferPrivateSession` when calling `signInWithRedirect()`
- remove gen2 callouts for installing aws-cdk-lib, constructs manually
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.