Created
January 27, 2021 20:11
-
-
Save RichardSPrins/14f47a7f5c03edbe1c8bb1c1f2ac2430 to your computer and use it in GitHub Desktop.
Login Page
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 * as React from "react"; | |
import { useRouter, useSession } from "blitz"; | |
import Layout from "app/layouts/Layout"; | |
import { LoginForm } from "app/auth/components/LoginForm"; | |
import { useCurrentUser } from "app/hooks/useCurrentUser" | |
const LoginPage = () => { | |
const session = useSession() | |
const handleLoginRedirect = (role) => { | |
if (!session.isLoading) { | |
switch (role) { | |
case 'RECRUITER': | |
router.push('/dashboard/company') | |
break; | |
case 'CANDIDATE': | |
router.push('/dashboard/candidate') | |
break; | |
default: | |
router.push('/') | |
break; | |
} | |
} | |
} | |
const router = useRouter(); | |
React.useEffect(() => { | |
if (!session.isLoading) { | |
if (session.userId) { | |
let role = session.roles[0] | |
handleLoginRedirect(role) | |
} | |
} | |
}, [session]) | |
return <div> | |
<LoginForm onSuccess={() => handleLoginRedirect(session.roles[0])} /> | |
</div>; | |
}; | |
LoginPage.getLayout = page => <Layout title="Log In">{page}</Layout>; | |
export default LoginPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment