summaryrefslogtreecommitdiff
path: root/src/lib/auth/components/LoginDesktop.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/auth/components/LoginDesktop.jsx')
-rw-r--r--src/lib/auth/components/LoginDesktop.jsx35
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'>