Skip to content

Instantly share code, notes, and snippets.

@zinedkaloc
Created August 8, 2022 11:46
Show Gist options
  • Save zinedkaloc/81a6bccfe959755da1fae99674d6bb65 to your computer and use it in GitHub Desktop.
Save zinedkaloc/81a6bccfe959755da1fae99674d6bb65 to your computer and use it in GitHub Desktop.
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