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/api/auth/[...nextauth].js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/pages/api/auth/[...nextauth].js (limited to 'src/pages/api/auth') 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/api/auth') 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 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/pages/api/auth') 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 }) -- 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/api/auth') 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