From 4d021a4634a6bc84ee25f0d43cbc6450d94265f0 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 31 Jul 2023 14:08:34 +0700 Subject: google sing up --- src/pages/_app.jsx | 8 +++++--- src/pages/api/auth/[...nextauth].js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/pages/api/auth/[...nextauth].js (limited to 'src/pages') diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index 4c4fed89..cda9e970 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -7,12 +7,14 @@ import { QueryClient, QueryClientProvider } from 'react-query' import useDevice from '@/core/hooks/useDevice' import { useEffect, useState } from 'react' import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' +import { SessionProvider } from 'next-auth/react' const queryClient = new QueryClient() -function MyApp({ Component, pageProps }) { +function MyApp({ Component, pageProps :{session, ...pageProps} }) { const router = useRouter() const { isMobile } = useDevice() + console.log('ini session', session) const [animateLoader, setAnimateLoader] = useState(false) @@ -47,7 +49,7 @@ function MyApp({ Component, pageProps }) { }, [isMobile]) return ( - <> + {animateLoader && ( } - + ) } diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js new file mode 100644 index 00000000..f1d6a31f --- /dev/null +++ b/src/pages/api/auth/[...nextauth].js @@ -0,0 +1,15 @@ +import NextAuth from "next-auth/next"; +import GoogleProvider from "next-auth/providers/google" + +export default NextAuth({ + providers:[ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET, + }), + ], + secret:process.env.JWT_SECRET + // pages:{ + // signIn: '/login', + // } +}) \ No newline at end of file -- cgit v1.2.3 From 4cfe9157d64a76bf9913fe599d908497a18f5316 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 9 Aug 2023 10:45:53 +0700 Subject: google sign in --- src/pages/api/auth/[...nextauth].js | 40 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/pages') diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index f1d6a31f..6cc8a101 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -1,15 +1,29 @@ -import NextAuth from "next-auth/next"; -import GoogleProvider from "next-auth/providers/google" +import NextAuth from 'next-auth/next' +import GoogleProvider from 'next-auth/providers/google' export default NextAuth({ - providers:[ - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - }), - ], - secret:process.env.JWT_SECRET - // pages:{ - // signIn: '/login', - // } -}) \ No newline at end of file + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET + }) + ], + callbacks: { + async jwt({ token, account }) { + // Persist the OAuth access_token to the token right after signin + if (account) { + token.accessToken = account.access_token + } + return token + }, + async session({ session, token, user }) { + // Send properties to the client, like an access_token from a provider. + session.accessToken = token.accessToken + return session + } + }, + secret:process.env.JWT_SECRET + // pages:{ + // signIn: '/login', + // } +}) -- cgit v1.2.3 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 --- src/pages/api/auth/[...nextauth].js | 13 +++++++------ src/pages/my/menu.jsx | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/pages') diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index 6cc8a101..b11ed097 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -1,3 +1,4 @@ +import odooApi from '@/core/api/odooApi' import NextAuth from 'next-auth/next' import GoogleProvider from 'next-auth/providers/google' @@ -10,20 +11,20 @@ export default NextAuth({ ], callbacks: { async jwt({ token, account }) { - // Persist the OAuth access_token to the token right after signin if (account) { token.accessToken = account.access_token } return token }, async session({ session, token, user }) { - // Send properties to the client, like an access_token from a provider. session.accessToken = token.accessToken + const params = { + access_token: session.accessToken + } + const data = await odooApi('POST', '/api/v1/user/validate-sso', params) + session.odooUser = data.user return session } }, - secret:process.env.JWT_SECRET - // pages:{ - // signIn: '/login', - // } + secret: process.env.JWT_SECRET }) diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx index c8e1e7e9..bd20e2eb 100644 --- a/src/pages/my/menu.jsx +++ b/src/pages/my/menu.jsx @@ -5,11 +5,13 @@ import useAuth from '@/core/hooks/useAuth' import { deleteAuth } from '@/core/utils/auth' import IsAuth from '@/lib/auth/components/IsAuth' import { ChevronRightIcon, UserIcon } from '@heroicons/react/24/solid' +import { signOut, useSession } from 'next-auth/react' import { useRouter } from 'next/router' export default function Menu() { const auth = useAuth() const router = useRouter() + const {data : session} = useSession() const logout = () => { deleteAuth() @@ -62,7 +64,7 @@ export default function Menu() { Daftar Alamat -
+
(logout, signOut)} className='p-4 mt-2'>
-- 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 --- src/pages/_app.jsx | 87 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 37 deletions(-) (limited to 'src/pages') diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index cda9e970..9f30752a 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -5,18 +5,29 @@ import { AnimatePresence, motion } from 'framer-motion' import { Toaster } from 'react-hot-toast' import { QueryClient, QueryClientProvider } from 'react-query' import useDevice from '@/core/hooks/useDevice' -import { useEffect, useState } from 'react' +import { createContext, useContext, useEffect, useState } from 'react' import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' import { SessionProvider } from 'next-auth/react' +import { getAuth } from '@/core/utils/auth' const queryClient = new QueryClient() -function MyApp({ Component, pageProps :{session, ...pageProps} }) { +export const AuthContext = createContext({ + authenticated : false, + setAuthenticated : (auth) => {} +}) + +function MyApp({ Component, pageProps: { session, ...pageProps } }) { const router = useRouter() const { isMobile } = useDevice() - console.log('ini session', session) const [animateLoader, setAnimateLoader] = useState(false) + const [authenticated, setAuthenticated] = useState(null) + const auth = getAuth() + + useEffect(() => { + setAuthenticated(auth) + }, [auth]) useEffect(() => { const handleRouteChangeStart = () => setAnimateLoader(true) @@ -49,41 +60,43 @@ function MyApp({ Component, pageProps :{session, ...pageProps} }) { }, [isMobile]) return ( - - - {animateLoader && ( - - - - )} - - - - - window.scrollTo(0, 0)} - > - {!animateLoader && } + + + + {animateLoader && ( + + + + )} - - + + + + window.scrollTo(0, 0)} + > + {!animateLoader && } + + + + ) } -- 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/pages/_app.jsx | 10 +++++----- src/pages/my/menu.jsx | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/pages') diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index 9f30752a..86cbe963 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -25,9 +25,9 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }) { const [authenticated, setAuthenticated] = useState(null) const auth = getAuth() - useEffect(() => { - setAuthenticated(auth) - }, [auth]) + // useEffect(() => { + // setAuthenticated(auth) + // }, [auth]) useEffect(() => { const handleRouteChangeStart = () => setAnimateLoader(true) @@ -60,7 +60,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }) { }, [isMobile]) return ( - + // {animateLoader && ( @@ -96,7 +96,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }) { - + // ) } diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx index bd20e2eb..fb8e6b03 100644 --- a/src/pages/my/menu.jsx +++ b/src/pages/my/menu.jsx @@ -11,11 +11,12 @@ import { useRouter } from 'next/router' export default function Menu() { const auth = useAuth() const router = useRouter() - const {data : session} = useSession() + const { data: session } = useSession() const logout = () => { - deleteAuth() - router.push('/login') + deleteAuth().then(() => { + router.push('/login') + }) } return ( @@ -64,7 +65,7 @@ export default function Menu() { Daftar Alamat -
(logout, signOut)} className='p-4 mt-2'> +
logout()} className='p-4 mt-2'>
-- 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/pages/api/auth/[...nextauth].js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/pages') diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index b11ed097..3c433167 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -18,11 +18,7 @@ export default NextAuth({ }, async session({ session, token, user }) { session.accessToken = token.accessToken - const params = { - access_token: session.accessToken - } - const data = await odooApi('POST', '/api/v1/user/validate-sso', params) - session.odooUser = data.user + return session } }, -- cgit v1.2.3