summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-08-14 15:04:45 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-08-14 15:04:45 +0700
commit01e86fb4a54b801a9b8124455611c312e5de4af0 (patch)
tree09733a6f9fff4c8624bd4a2f2c514d8b16cc684b /src/core
parent4cfe9157d64a76bf9913fe599d908497a18f5316 (diff)
google sign in
Diffstat (limited to 'src/core')
-rw-r--r--src/core/components/elements/Navbar/NavbarDesktop.jsx5
-rw-r--r--src/core/components/elements/Navbar/NavbarUserDropdown.jsx8
-rw-r--r--src/core/components/layouts/BasicLayout.jsx93
-rw-r--r--src/core/utils/auth.js4
4 files changed, 68 insertions, 42 deletions
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index ea4b03ae..c6575831 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -17,9 +17,10 @@ import { getCountCart } from '@/core/utils/cart'
import TopBanner from './TopBanner'
import whatsappUrl from '@/core/utils/whatsappUrl'
import { useRouter } from 'next/router'
-import { getAuth } from '@/core/utils/auth'
+import { getAuth, setAuth } from '@/core/utils/auth'
import { createSlug, getIdFromSlug } from '@/core/utils/slug'
import productApi from '@/lib/product/api/productApi'
+import { useSession } from 'next-auth/react'
const Search = dynamic(() => import('./Search'))
@@ -33,7 +34,7 @@ const NavbarDesktop = () => {
const [payloadWA, setPayloadWa] = useState(null)
const router = useRouter()
-
+
useEffect(() => {
const handleCartChange = () => {
const cart = async () => {
diff --git a/src/core/components/elements/Navbar/NavbarUserDropdown.jsx b/src/core/components/elements/Navbar/NavbarUserDropdown.jsx
index 7848124c..b58be493 100644
--- a/src/core/components/elements/Navbar/NavbarUserDropdown.jsx
+++ b/src/core/components/elements/Navbar/NavbarUserDropdown.jsx
@@ -1,13 +1,15 @@
import { deleteAuth } from '@/core/utils/auth'
import Link from '../Link/Link'
import { useRouter } from 'next/router'
+import { signOut, useSession } from 'next-auth/react'
const NavbarUserDropdown = () => {
const router = useRouter()
- const logout = () => {
- deleteAuth()
- router.push('/login')
+ const logout = async () => {
+ deleteAuth().then(() => {
+ router.push('/login')
+ })
}
return (
diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx
index 073303fe..e8f6434b 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -6,10 +6,11 @@ import { useEffect, useState } from 'react'
import axios from 'axios'
import odooApi from '@/core/api/odooApi'
import { useRouter } from 'next/router'
-import { getURL } from 'next/dist/shared/lib/utils'
import productApi from '@/lib/product/api/productApi'
-import { getAuth } from '@/core/utils/auth'
+import { getAuth, setAuth } from '@/core/utils/auth'
import { createSlug, getIdFromSlug } from '@/core/utils/slug'
+import { useSession } from 'next-auth/react'
+import { setCookie } from 'cookies-next'
const Navbar = dynamic(() => import('../elements/Navbar/Navbar'))
const AnimationLayout = dynamic(() => import('./AnimationLayout'))
@@ -17,10 +18,26 @@ const AnimationLayout = dynamic(() => import('./AnimationLayout'))
const BasicLayout = ({ children }) => {
const [templateWA, setTemplateWA] = useState(null)
const [payloadWA, setPayloadWa] = useState(null)
+ const [isLoading, setIsloading] = useState(false)
const router = useRouter()
+ const { data: session } = useSession()
+ const auth = getAuth()
+ const setting = async () => {
+ if (!auth && session) {
+ setCookie('auth', JSON.stringify(session?.odooUser))
+ setIsloading(false)
+ }
+ }
+
+ useEffect(() => {
+ setting()
+ }, [session])
useEffect(() => {
+ setting()
+ console.log('ini session', session)
+ console.log('ini auth', getAuth())
const getIP = async () => {
const ip = await odooApi('GET', '/api/ip-address')
const data = {
@@ -46,42 +63,46 @@ const BasicLayout = ({ children }) => {
}
getProduct()
setTemplateWA('product')
-
}
}, [])
- return (
- <>
- <Navbar />
- <AnimationLayout>
- {children}
- <div className='fixed bottom-4 right-4 sm:bottom-14 sm:right-10 z-50'>
- <a
- href={whatsappUrl(templateWA, payloadWA)}
- className='py-2 pl-3 pr-4 rounded-full bg-[#4FB84A] border border-green-300 flex items-center'
- rel='noopener noreferrer'
- target='_blank'
- >
- <Image
- src='/images/socials/WHATSAPP.svg'
- alt='Whatsapp'
- className='block sm:hidden'
- width={36}
- height={36}
- />
- <Image
- src='/images/socials/WHATSAPP.svg'
- alt='Whatsapp'
- className='hidden sm:block'
- width={44}
- height={44}
- />
- <span className='text-white font-bold ml-1.5'>Whatsapp</span>
- </a>
- </div>
- </AnimationLayout>
- <BasicFooter />
- </>
- )
+ if(isLoading){
+
+ }else{
+ return (
+ <>
+ <Navbar />
+ <AnimationLayout>
+ {children}
+ <div className='fixed bottom-4 right-4 sm:bottom-14 sm:right-10 z-50'>
+ <a
+ href={whatsappUrl(templateWA, payloadWA)}
+ className='py-2 pl-3 pr-4 rounded-full bg-[#4FB84A] border border-green-300 flex items-center'
+ rel='noopener noreferrer'
+ target='_blank'
+ >
+ <Image
+ src='/images/socials/WHATSAPP.svg'
+ alt='Whatsapp'
+ className='block sm:hidden'
+ width={36}
+ height={36}
+ />
+ <Image
+ src='/images/socials/WHATSAPP.svg'
+ alt='Whatsapp'
+ className='hidden sm:block'
+ width={44}
+ height={44}
+ />
+ <span className='text-white font-bold ml-1.5'>Whatsapp</span>
+ </a>
+ </div>
+ </AnimationLayout>
+ <BasicFooter />
+ </>
+ )
+ }
+
}
export default BasicLayout
diff --git a/src/core/utils/auth.js b/src/core/utils/auth.js
index cddff2b8..03b20ae2 100644
--- a/src/core/utils/auth.js
+++ b/src/core/utils/auth.js
@@ -1,4 +1,5 @@
import { deleteCookie, getCookie, setCookie } from 'cookies-next'
+import { signOut } from 'next-auth/react'
/**
* Retrieves authentication data from cookie and returns it as an object.
@@ -27,7 +28,8 @@ const setAuth = (user) => {
*
* @returns {boolean} - Returns `true`.
*/
-const deleteAuth = () => {
+const deleteAuth = async() => {
+ await signOut()
deleteCookie('auth')
return true
}