Skip to content

Instantly share code, notes, and snippets.

@wlee221
Created July 15, 2021 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlee221/3361924b364974af42ce17d2fa53dc27 to your computer and use it in GitHub Desktop.
Save wlee221/3361924b364974af42ce17d2fa53dc27 to your computer and use it in GitHub Desktop.
import Amplify from "aws-amplify";
import {
CognitoUserInterface,
onAuthUIStateChange,
AuthState,
} from "@aws-amplify/ui-components";
import { AmplifyAuthenticator, AmplifyTotpSetup } from "@aws-amplify/ui-react";
import { useEffect, useState } from "react";
Amplify.configure({ /** redacted */ });
function App() {
const [user, setUser] = useState<CognitoUserInterface>();
const [authState, setAuthState] = useState<AuthState>();
useEffect(() => {
onAuthUIStateChange((authState, authUser) => {
setUser(authUser as CognitoUserInterface);
setAuthState(authState);
});
}, []);
return (
<>
{authState !== AuthState.SignedIn ? (
<AmplifyAuthenticator />
) : (
<AmplifyTotpSetup user={user} />
)}
</>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment