From 9a33f3a391a402807cc5e7913b1a97e430a7aaa2 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 15 Aug 2023 15:16:38 +0700 Subject: sign in --- .../components/elements/Navbar/NavbarDesktop.jsx | 10 ++- src/core/components/layouts/BasicLayout.jsx | 87 ++++++++++------------ 2 files changed, 44 insertions(+), 53 deletions(-) (limited to 'src/core') diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index c6575831..06c15b73 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -10,7 +10,7 @@ import DesktopView from '../../views/DesktopView' import dynamic from 'next/dynamic' import IndoteknikLogo from '@/images/logo.png' import Category from '@/lib/category/components/Category' -import { useEffect, useState } from 'react' +import { useContext, useEffect, useState } from 'react' import useAuth from '@/core/hooks/useAuth' import NavbarUserDropdown from './NavbarUserDropdown' import { getCountCart } from '@/core/utils/cart' @@ -21,11 +21,13 @@ 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' +import { AuthContext } from '@/pages/_app' const Search = dynamic(() => import('./Search')) const NavbarDesktop = () => { const [isOpenCategory, setIsOpenCategory] = useState(false) + const {authenticated} = useContext(AuthContext) const auth = useAuth() const [cartCount, setCartCount] = useState(0) @@ -177,7 +179,7 @@ const NavbarDesktop = () => {
- {!auth && ( + {!authenticated && ( <> { )} - {auth && ( + {authenticated && ( <>
- Halo, {auth?.name} + Halo, {authenticated?.name}
diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index e8f6434b..e5c6908a 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -18,26 +18,20 @@ 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) - } + setCookie('auth', JSON.stringify(session?.odooUser)) } useEffect(() => { - setting() - }, [session]) - - useEffect(() => { - setting() + // if (!auth && session) { + // setting() + // } + console.log('ini auth', auth) console.log('ini session', session) - console.log('ini auth', getAuth()) const getIP = async () => { const ip = await odooApi('GET', '/api/ip-address') const data = { @@ -65,44 +59,39 @@ const BasicLayout = ({ children }) => { setTemplateWA('product') } }, []) - if(isLoading){ - - }else{ - return ( - <> - - - {children} - - - - - ) - } - + return ( + <> + + + {children} + + + + + ) } export default BasicLayout -- cgit v1.2.3