From b6f6bf23f90ff0dfadf9bf0af8866c2cfc17aa9c Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 18 Aug 2023 11:02:39 +0700
Subject: handling redirect login

---
 src/lib/auth/components/LoginMobile.jsx | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

(limited to 'src/lib/auth/components/LoginMobile.jsx')

diff --git a/src/lib/auth/components/LoginMobile.jsx b/src/lib/auth/components/LoginMobile.jsx
index 68ceb769..095f4174 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -9,27 +9,41 @@ import { useSession, signIn, SignOut } from 'next-auth/react'
 import { useRouter } from 'next/router'
 import { useEffect, useState } from 'react'
 import { setCookie } from 'cookies-next'
+import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
+import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'
+import odooApi from '@/core/api/odooApi'
+import { getAuth } from '@/core/utils/auth'
 
 const LoginMobile = () => {
-  const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } =
+  const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef, handleGoogleSubmit } =
     useLogin()
 
   const router = useRouter()
   const [query, setQuery] = useState(router?.query?.next || '/')
   const { data: session } = useSession()
+  const auth = getAuth()
 
   const handleGoogle = async () => {
-    const url = query != '/' ? '/login?next=' + query : '/login'
+    const url = query != '/' ? '/login?source=google&next=' + query : '/login?source=google'
     await signIn('google', { callbackUrl: url })
-    setCookie('auth', JSON.stringify(session?.odooUser))
   }
   useEffect(() => {
     if (session) {
-      setCookie('auth', JSON.stringify(session?.odooUser))
-      router.push(query)
+      handleGoogleSubmit(session)
     }
   }, [session])
 
+  if (router.query.source) {
+    return (
+      <BottomPopup active={true} close={true}>
+        <div className='leading-7 text-gray_r-12/80 flex justify-center'>Mohon Tunggu</div>
+        <div className='container flex justify-center my-4'>
+          <LogoSpinner width={48} height={48} />
+        </div>
+      </BottomPopup>
+    )
+  }
+
   return (
     <MobileView>
       <div className='p-6 pt-10 flex flex-col items-center min-h-screen'>
-- 
cgit v1.2.3

