diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-16 09:39:47 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-16 09:39:47 +0700 |
| commit | f01f28a7eac76c6da5bf857bfc80fd347586ce7f (patch) | |
| tree | 0e7b587eeb0162852565dfa97d3c35d1354d8c21 /src/lib/auth/components/LoginMobile.jsx | |
| parent | 9a33f3a391a402807cc5e7913b1a97e430a7aaa2 (diff) | |
register google
Diffstat (limited to 'src/lib/auth/components/LoginMobile.jsx')
| -rw-r--r-- | src/lib/auth/components/LoginMobile.jsx | 17 |
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' |
