diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-09-01 02:34:28 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-09-01 02:34:28 +0000 |
| commit | da727c41d5221e13389005dbdff2706d3eb42842 (patch) | |
| tree | 2abb9a8090306791a76069baff6c91c5e151d3b5 /src/core | |
| parent | 7356bcc0d1b7bac8d05ac315fdcf2a46b3996e91 (diff) | |
| parent | dfdeedf7141c9191952bdb3005e2e91d2a495044 (diff) | |
Merged in Feature/google_sign_up (pull request #56)
Feature/google sign up
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/components/elements/Navbar/NavbarDesktop.jsx | 9 | ||||
| -rw-r--r-- | src/core/components/elements/Navbar/NavbarUserDropdown.jsx | 8 | ||||
| -rw-r--r-- | src/core/components/layouts/BasicLayout.jsx | 5 | ||||
| -rw-r--r-- | src/core/utils/auth.js | 4 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index acd2d1ee..6fdea644 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -10,15 +10,17 @@ 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' 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' +import { AuthContext } from '@/pages/_app' import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton' const Search = dynamic(() => import('./Search')) @@ -28,6 +30,7 @@ const TopBanner = dynamic(() => import('./TopBanner'), { const NavbarDesktop = () => { const [isOpenCategory, setIsOpenCategory] = useState(false) + const {authenticated} = useContext(AuthContext) const auth = useAuth() const [cartCount, setCartCount] = useState(0) @@ -36,7 +39,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 2e98eb61..e737101a 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')) 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 } |
