-
Notifications
You must be signed in to change notification settings - Fork 318
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
Examples on new <Authenticator/> instead of the HOC withAuthenticator, migration docs. #640
Comments
@artidata I totally agree. We'll roll this in with #576 & #254. So the primary usage will look like: amplify-ui/examples/next/pages/ui/components/authenticator/sign-up-with-attributes/index.page.tsx Lines 3 to 15 in f84e994
This is different than the previous As for
You're feedback has been really helpful. Can you share an example of how you're using |
My use case is almost a copy paste of the docs import React from 'react';
import './App.css';
import Amplify from 'aws-amplify';
import { AmplifyAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react';
import { AuthState, onAuthUIStateChange } from '@aws-amplify/ui-components';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
const AuthStateApp = () => {
const [authState, setAuthState] = React.useState();
const [user, setUser] = React.useState();
React.useEffect(() => {
return onAuthUIStateChange((nextAuthState, authData) => {
setAuthState(nextAuthState);
setUser(authData)
});
}, []);
return authState === AuthState.SignedIn && user ? (
<div className="App">
<div>Hello, {user.username}</div>
<AmplifySignOut />
</div>
) : (
<AmplifyAuthenticator />
);
}
export default AuthStateApp; Instead of the rest of the app to be the |
export default function SimpleApp() {
return (
<Authenticator>
{({ signOut, user }) => (
<div className="App">
<div>Hello, {user.username}</div>
<button onClick={signOut}>Sign out</button>
</div>
)}
</Authenticator>
);
} No need to manage state separately – it's all passed directly to the inner function. In fact, this is how it's being used internally:
One important thing to note between the previous This release fixes that design so that We'll update the docs to mention |
As much as I like the new design and its extensive configuration, I will prefer the latest stable release approach with
AuthState
andonAuthUIStateChange
as seen in this docs: https://docs.amplify.aws/ui/auth/authenticator/q/framework/react/#recommended-usage.Using the past
<AmplifyAuthenticator/>
is more component composition friendly compared to the new HOCwithAuthenticator
. I guess the new UI is not backward compatible as I have tried to simply replace<AmplifyAuthenticator/>
with the new<Authenticator/>
, but it doesn't work. Will you support the Authstate approach or withAuthenticator is the only future?The text was updated successfully, but these errors were encountered: