Created
July 15, 2021 02:06
-
-
Save wlee221/3361924b364974af42ce17d2fa53dc27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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