Created
August 8, 2022 11:46
-
-
Save zinedkaloc/81a6bccfe959755da1fae99674d6bb65 to your computer and use it in GitHub Desktop.
This file contains 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 React, { useEffect, useState } from 'react'; | |
import { altogic } from '../helpers/altogic'; | |
import { useNavigate } from 'react-router-dom'; | |
import { useAuth } from '../contexts/Auth'; | |
export function Redirect() { | |
const navigate = useNavigate(); | |
const { session, setSession, setUser } = useAuth(); | |
const [errors, setError] = useState(null); | |
useEffect(() => { | |
async function fetchData() { | |
let { session, user, errors } = await altogic.auth.getAuthGrant(); | |
setSession(session); | |
setUser(user); | |
// If error occurs, set error state | |
if (errors) return setError(errors); | |
navigate('/'); | |
console.log('session', session); | |
} | |
fetchData(); | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, []); | |
return !session ? ( | |
<div style={{ margin: '20px 20px' }}> | |
You are redirecting to the profile page... | |
</div> | |
) : ( | |
<div style={{ margin: '20px 20px' }}> | |
Not verified... | |
<pre>{errors && JSON.stringify(errors, null, 3)}</pre> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment