diff --git a/.env b/.env index a11d12b..44ab9ff 100644 --- a/.env +++ b/.env @@ -1,2 +1,6 @@ AUTH_SECRET=Gh0jQ35oq6DR8HkLR3heA8EaEDtxYN/xkP6blvukZ0w= -MONGODB_URI=mongodb://root:example@localhost:27017/ \ No newline at end of file +MONGODB_URI=mongodb://root:example@localhost:27017/ + +GOOGLE_ID=355397364527-adjrokm6hromcaaar0qfhk050mfr35ou.apps.googleusercontent.com +GOOGLE_SECRET=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 +NEXT_AUTH_SECRET=Gh0jQ35oq6DR8HkLR3heA8EaEDtxYN/xkP6blvukZ0w= diff --git a/README.md b/README.md index 89bc89e..596249f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ * infinite scroll * https://stackoverflow.com/questions/67624601/how-to-implement-infinite-scroll-in-next-js * authentication with Google - * https://www.telerik.com/blogs/how-to-implement-google-authentication-nextjs-app-using-nextauth* multi-user support + * https://www.telerik.com/blogs/how-to-implement-google-authentication-nextjs-app-using-nextauth +* multi-user support * bill amount entry * monthly bill amount summery * build & deploy via docker diff --git a/auth.config.ts b/auth.config.db.ts similarity index 100% rename from auth.config.ts rename to auth.config.db.ts diff --git a/auth.config.google.ts b/auth.config.google.ts new file mode 100644 index 0000000..ebdab15 --- /dev/null +++ b/auth.config.google.ts @@ -0,0 +1,17 @@ +import NextAuth, { NextAuthConfig } from 'next-auth'; +import GoogleProvider from 'next-auth/providers/google'; + +export const authConfig:NextAuthConfig = { + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_ID, + clientSecret: process.env.GOOGLE_SECRET, + }), + ], + session: { + // Use JSON Web Tokens for session instead of database sessions. + // This option can be used with or without a database for users/accounts. + // Note: `jwt` is automatically set to `true` if no database is specified. + strategy: 'jwt' + }, +}; \ No newline at end of file diff --git a/auth.ts b/auth.ts index d2f57c7..f134a8f 100644 --- a/auth.ts +++ b/auth.ts @@ -4,7 +4,7 @@ * @exports exports `auth`, `signIn`, `signOut` actions */ import NextAuth from 'next-auth'; -import { authConfig } from './auth.config'; +import { authConfig } from './auth.config.db'; import Credentials from 'next-auth/providers/credentials'; import { z } from 'zod'; // import bcrypt from 'bcrypt'; diff --git a/client_secret.apps.googleusercontent.com.json b/client_secret.apps.googleusercontent.com.json new file mode 100644 index 0000000..e1a44b2 --- /dev/null +++ b/client_secret.apps.googleusercontent.com.json @@ -0,0 +1,16 @@ +{ + "web": { + "client_id": "355397364527-adjrokm6hromcaaar0qfhk050mfr35ou.apps.googleusercontent.com", + "project_id": "evidencija-rezija", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_secret": "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", + "redirect_uris": [ + "http://localhost:3000/api/auth/callback/google" + ], + "javascript_origins": [ + "http://localhost:3000" + ] + } +} \ No newline at end of file diff --git a/middleware.ts b/middleware.ts index 9fb76f6..fca5472 100644 --- a/middleware.ts +++ b/middleware.ts @@ -4,7 +4,7 @@ */ import NextAuth from 'next-auth'; -import { authConfig } from './auth.config'; +import { authConfig } from './auth.config.db'; export default NextAuth(authConfig).auth;