summaryrefslogtreecommitdiff
path: root/src/lib/auth/components/LoginMobile.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/auth/components/LoginMobile.jsx')
-rw-r--r--src/lib/auth/components/LoginMobile.jsx17
1 files changed, 13 insertions, 4 deletions
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'