Skip to content

Instantly share code, notes, and snippets.

@ilyador
Last active February 20, 2020 19:58
Show Gist options
  • Save ilyador/306677e49fc66d22a0b097a68adb8650 to your computer and use it in GitHub Desktop.
Save ilyador/306677e49fc66d22a0b097a68adb8650 to your computer and use it in GitHub Desktop.
auth with router
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