From f01f28a7eac76c6da5bf857bfc80fd347586ce7f Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 16 Aug 2023 09:39:47 +0700
Subject: register google

---
 src/lib/auth/components/LoginMobile.jsx | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 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 c5177625..68ceb769 100644
--- a/src/lib/auth/components/LoginMobile.jsx
+++ b/src/lib/auth/components/LoginMobile.jsx
@@ -7,7 +7,8 @@ import useLogin from '../hooks/useLogin'
 
 import { useSession, signIn, SignOut } from 'next-auth/react'
 import { useRouter } from 'next/router'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
+import { setCookie } from 'cookies-next'
 
 const LoginMobile = () => {
   const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } =
@@ -17,9 +18,17 @@ const LoginMobile = () => {
   const [query, setQuery] = useState(router?.query?.next || '/')
   const { data: session } = useSession()
 
-  if (session) {
-    router.push(query)
+  const handleGoogle = async () => {
+    const url = query != '/' ? '/login?next=' + query : '/login'
+    await signIn('google', { callbackUrl: url })
+    setCookie('auth', JSON.stringify(session?.odooUser))
   }
+  useEffect(() => {
+    if (session) {
+      setCookie('auth', JSON.stringify(session?.odooUser))
+      router.push(query)
+    }
+  }, [session])
 
   return (
     <MobileView>
@@ -77,7 +86,7 @@ const LoginMobile = () => {
         <button
           type='submit'
           className='border border-gray-500 p-2 rounded-md hover:bg-gray-100  w-full mt-2 flex items-center justify-center gap-x-2'
-          onClick={() => signIn('google',  { callbackUrl: '/login' })}
+          onClick={() => handleGoogle()}
         >
           <Image
             src='/images/icons8-google.svg'
-- 
cgit v1.2.3

