From 01e86fb4a54b801a9b8124455611c312e5de4af0 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 14 Aug 2023 15:04:45 +0700 Subject: google sign in --- .../components/elements/Navbar/NavbarDesktop.jsx | 5 +- .../elements/Navbar/NavbarUserDropdown.jsx | 8 +- src/core/components/layouts/BasicLayout.jsx | 93 +++++++++++++--------- src/core/utils/auth.js | 4 +- 4 files changed, 68 insertions(+), 42 deletions(-) (limited to 'src/core') 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 ( - <> - - - {children} -
- - Whatsapp - Whatsapp - Whatsapp - -
-
- - - ) + if(isLoading){ + + }else{ + return ( + <> + + + {children} + + + + + ) + } + } 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 } -- cgit v1.2.3 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 From f01f28a7eac76c6da5bf857bfc80fd347586ce7f Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 16 Aug 2023 09:39:47 +0700 Subject: register google --- src/core/components/elements/Navbar/NavbarDesktop.jsx | 6 +++--- src/core/components/layouts/BasicLayout.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index 06c15b73..17aedeb6 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -179,7 +179,7 @@ const NavbarDesktop = () => {
- {!authenticated && ( + {!auth && ( <> { )} - {authenticated && ( + {auth && ( <>
- Halo, {authenticated?.name} + Halo, {auth?.name}
diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index e5c6908a..0fea1a3b 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -27,9 +27,9 @@ const BasicLayout = ({ children }) => { } useEffect(() => { - // if (!auth && session) { - // setting() - // } + if (!auth && session) { + setting() + } console.log('ini auth', auth) console.log('ini session', session) const getIP = async () => { -- cgit v1.2.3 From b6f6bf23f90ff0dfadf9bf0af8866c2cfc17aa9c Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 18 Aug 2023 11:02:39 +0700 Subject: handling redirect login --- src/core/components/layouts/BasicLayout.jsx | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/core') diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index 0fea1a3b..272440c2 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -20,18 +20,8 @@ const BasicLayout = ({ children }) => { const [payloadWA, setPayloadWa] = useState(null) const router = useRouter() - const { data: session } = useSession() - const auth = getAuth() - const setting = async () => { - setCookie('auth', JSON.stringify(session?.odooUser)) - } useEffect(() => { - if (!auth && session) { - setting() - } - console.log('ini auth', auth) - console.log('ini session', session) const getIP = async () => { const ip = await odooApi('GET', '/api/ip-address') const data = { -- cgit v1.2.3 From e6feac8e6ce2ea3c428d4307251634708b676c25 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 23 Aug 2023 17:03:23 +0700 Subject: page daftar pengiriman --- src/core/components/elements/Navbar/NavbarUserDropdown.jsx | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core') diff --git a/src/core/components/elements/Navbar/NavbarUserDropdown.jsx b/src/core/components/elements/Navbar/NavbarUserDropdown.jsx index 7848124c..075462e9 100644 --- a/src/core/components/elements/Navbar/NavbarUserDropdown.jsx +++ b/src/core/components/elements/Navbar/NavbarUserDropdown.jsx @@ -15,6 +15,7 @@ const NavbarUserDropdown = () => {
Daftar Quotation Daftar Transaksi + Daftar Pengiriman Invoice & Faktur Pajak Wishlist Daftar Alamat -- cgit v1.2.3 From 7322c0ad2e8764c7c1e6100c93690d24cd4ab947 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 1 Sep 2023 13:53:42 +0700 Subject: comment sign out google --- src/core/utils/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/utils/auth.js b/src/core/utils/auth.js index 03b20ae2..a7244747 100644 --- a/src/core/utils/auth.js +++ b/src/core/utils/auth.js @@ -29,7 +29,7 @@ const setAuth = (user) => { * @returns {boolean} - Returns `true`. */ const deleteAuth = async() => { - await signOut() + // await signOut() deleteCookie('auth') return true } -- cgit v1.2.3