-
Notifications
You must be signed in to change notification settings - Fork 998
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
Clarification needed on how to prevent Authenticator from pre-rendering component #269
Comments
Yeah it's not clear. If you're just looking to render your own component (let's say 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 One more thing, you don't need |
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 |
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. |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
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;
} |
This is still an issue; Do I have to create a new ticket for this, as it's been marked stale? |
Still finding this very confusing. I'm also confused why |
Does anyone know how to do it with functional component? It's been 2 years now but documentation is still confusing. |
@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
You can assign props |
The documentation isn't clear on how to configure an Authenticator component so that the content it wraps is only rendered after a successful login.
The documentation can be found here: https://aws-amplify.github.io/docs/js/authentication#show-your-app-after-sign-in
Specifically, the part of this that isn't clear is
Where is
this._validAuthStates=['signedIn']
supposed to be written/set? Additionally, where can any further documentation on swappingshowComponent(theme) {}
instead ofrender()
be found?Any help would be appreciated. In fact, if someone can provide clarification I will submit a PR that updates the documentation.
The text was updated successfully, but these errors were encountered: