diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-15 15:16:38 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-15 15:16:38 +0700 |
| commit | 9a33f3a391a402807cc5e7913b1a97e430a7aaa2 (patch) | |
| tree | e603b6e5e321a78af52fca2e7187c17a13d3deb4 /src/lib/auth/components | |
| parent | 01e86fb4a54b801a9b8124455611c312e5de4af0 (diff) | |
sign in
Diffstat (limited to 'src/lib/auth/components')
| -rw-r--r-- | src/lib/auth/components/LoginDesktop.jsx | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/lib/auth/components/LoginDesktop.jsx b/src/lib/auth/components/LoginDesktop.jsx index e3bff492..06c90d45 100644 --- a/src/lib/auth/components/LoginDesktop.jsx +++ b/src/lib/auth/components/LoginDesktop.jsx @@ -6,8 +6,10 @@ import Alert from '@/core/components/elements/Alert/Alert' import { useSession, signIn, SignOut } from 'next-auth/react' import Image from 'next/image' import { useRouter } from 'next/router' -import { useEffect, useState } from 'react' +import { useContext, useEffect, useState } from 'react' import Spinner from '@/core/components/elements/Spinner/Spinner' +import { AuthContext } from '@/pages/_app' +import { getAuth, setAuth } from '@/core/utils/auth' const LoginDesktop = () => { const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } = @@ -16,37 +18,20 @@ const LoginDesktop = () => { const router = useRouter() const [query, setQuery] = useState(router?.query?.next || '/') const { data: session } = useSession() - const [googleLoading, setGoogleloading] = useState(true) - - useEffect(() => { - // Simulate loading for 2 seconds - const delay = setTimeout(() => { - setGoogleloading(false); - }, 3000); - - return () => { - clearTimeout(delay); // Clear the timeout if the component unmounts - }; - }, []); - + const auth = getAuth() + const { setAuthenticated } = useContext(AuthContext) const handleGoogle = async () => { - await signIn('google', { callbackUrl: '/login' }) + const url = query != '/' ? '/login?next=' + query : '/login' + await signIn('google', { callbackUrl: url }) } useEffect(() => { - if (session) { - router.push(query) + if (session || auth) { + setAuthenticated(session ? session.odooUser : auth) } - }, [session, query]) + }, [session]) - if (googleLoading) { - return ( - <div className='flex justify-center my-6'> - <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' /> - </div> - ) - } return ( <DesktopView> <div className='container mx-auto'> |
