Last active
February 20, 2020 19:58
-
-
Save ilyador/306677e49fc66d22a0b097a68adb8650 to your computer and use it in GitHub Desktop.
auth with router
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
function App () { | |
const [user, setUser] = useState(null) | |
const [authenticating, setAuthenticating] = useState(true) | |
useEffect(() => { | |
Auth.currentAuthenticatedUser() | |
.then(data => { setUser(data.attributes) }) | |
.catch(error => { console.log(error) }) | |
.finally(() => { setAuthenticating(false) }) | |
}, []) | |
const updateUserState = async user => { | |
setUser(user) | |
} | |
return ( | |
authenticating ? ( | |
<div className={c.wrapper}> | |
<Loader size={60}/> | |
</div> | |
) : ( | |
<Routes | |
user={user} | |
updateUserState={updateUserState} | |
/> | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment