From 9a33f3a391a402807cc5e7913b1a97e430a7aaa2 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 15 Aug 2023 15:16:38 +0700 Subject: sign in --- src/lib/auth/components/LoginDesktop.jsx | 35 +++++++++----------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/lib/auth/components/LoginDesktop.jsx') 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 ( -
- -
- ) - } return (
-- cgit v1.2.3