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 | |
| parent | 9a33f3a391a402807cc5e7913b1a97e430a7aaa2 (diff) | |
register google
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/auth/components/LoginDesktop.jsx | 11 | ||||
| -rw-r--r-- | src/lib/auth/components/LoginMobile.jsx | 17 | ||||
| -rw-r--r-- | src/lib/auth/components/RegisterDesktop.jsx | 39 | ||||
| -rw-r--r-- | src/lib/auth/components/RegisterMobile.jsx | 39 |
4 files changed, 96 insertions, 10 deletions
diff --git a/src/lib/auth/components/LoginDesktop.jsx b/src/lib/auth/components/LoginDesktop.jsx index 06c90d45..3a7477b9 100644 --- a/src/lib/auth/components/LoginDesktop.jsx +++ b/src/lib/auth/components/LoginDesktop.jsx @@ -7,9 +7,8 @@ import { useSession, signIn, SignOut } from 'next-auth/react' import Image from 'next/image' import { useRouter } from 'next/router' 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' +import { setCookie } from 'cookies-next' const LoginDesktop = () => { const { handleSubmit, handleChangeInput, isLoading, isValid, alert, emailRef, passwordRef } = @@ -19,7 +18,6 @@ const LoginDesktop = () => { const [query, setQuery] = useState(router?.query?.next || '/') const { data: session } = useSession() const auth = getAuth() - const { setAuthenticated } = useContext(AuthContext) const handleGoogle = async () => { const url = query != '/' ? '/login?next=' + query : '/login' @@ -27,10 +25,11 @@ const LoginDesktop = () => { } useEffect(() => { - if (session || auth) { - setAuthenticated(session ? session.odooUser : auth) + if(session){ + setCookie('auth', JSON.stringify(session?.odooUser)) + router.push(query) } - }, [session]) + },[session]) return ( <DesktopView> 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' diff --git a/src/lib/auth/components/RegisterDesktop.jsx b/src/lib/auth/components/RegisterDesktop.jsx index 93b505ab..86a5027d 100644 --- a/src/lib/auth/components/RegisterDesktop.jsx +++ b/src/lib/auth/components/RegisterDesktop.jsx @@ -5,6 +5,11 @@ import Alert from '@/core/components/elements/Alert/Alert' import PageContent from '@/lib/content/components/PageContent' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' import ReCAPTCHA from 'react-google-recaptcha' +import Image from 'next/image' +import { useEffect } from 'react' +import { setCookie } from 'cookies-next' +import { signIn, useSession } from 'next-auth/react' +import { useRouter } from 'next/router' const RegisterDesktop = () => { const { @@ -21,6 +26,20 @@ const RegisterDesktop = () => { tnd, setTnd } = useRegister() + + const { data: session } = useSession() + const router = useRouter() + + const handleGoogle = async () => { + await signIn('google', { callbackUrl: '/register' }) + } + + useEffect(() => { + if(session){ + setCookie('auth', JSON.stringify(session?.odooUser)) + router.push('/') + } + },[session]) return ( <DesktopView> @@ -121,6 +140,26 @@ const RegisterDesktop = () => { <PageContent path='/register#tnd'></PageContent> </BottomPopup> </div> + <div className='flex items-center mt-3 mb-3'> + <hr className='flex-1' /> + <p className='text-gray-400'>ATAU</p> + <hr className='flex-1' /> + </div> + + <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={() => handleGoogle()} + > + <Image + src='/images/icons8-google.svg' + alt='google image' + className='h-7 w-7' + width={10} + height={10} + /> + <p>Daftar dengan Google</p> + </button> <div className='text-gray_r-11 mt-10'> Sudah punya akun Indoteknik?{' '} diff --git a/src/lib/auth/components/RegisterMobile.jsx b/src/lib/auth/components/RegisterMobile.jsx index da6efaf5..c21c9325 100644 --- a/src/lib/auth/components/RegisterMobile.jsx +++ b/src/lib/auth/components/RegisterMobile.jsx @@ -7,6 +7,10 @@ import MobileView from '@/core/components/views/MobileView' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' import PageContent from '@/lib/content/components/PageContent' import ReCAPTCHA from 'react-google-recaptcha' +import { signIn, useSession } from 'next-auth/react' +import { useRouter } from 'next/router' +import { setCookie } from 'cookies-next' +import { useEffect } from 'react' const RegisterMobile = () => { const { @@ -24,6 +28,20 @@ const RegisterMobile = () => { setTnd } = useRegister() + const { data: session } = useSession() + const router = useRouter() + + const handleGoogle = async () => { + await signIn('google', { callbackUrl: '/register' }) + } + + useEffect(() => { + if(session){ + setCookie('auth', JSON.stringify(session?.odooUser)) + router.push('/') + } + },[session]) + return ( <MobileView> <div className='p-6 pt-10 flex flex-col items-center min-h-screen'> @@ -122,6 +140,27 @@ const RegisterMobile = () => { </BottomPopup> </div> + <div className='flex items-center mt-3 mb-3'> + <hr className='flex-1' /> + <p className='text-gray-400'>ATAU</p> + <hr className='flex-1' /> + </div> + + <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={() => handleGoogle()} + > + <Image + src='/images/icons8-google.svg' + alt='google image' + className='h-7 w-7' + width={10} + height={10} + /> + <p>Daftar dengan Google</p> + </button> + <div className='text-gray_r-11 mt-4'> Sudah punya akun Indoteknik?{' '} <Link href='/login' className='inline'> |
