diff --git a/.vscode/launch.json b/.vscode/launch.json index 41839db..2772a38 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,6 +9,11 @@ "type": "node", "request": "launch", "envFile": "${workspaceFolder}/.env", + "env": { + "USE_MOCK_AUTH": "true", + "MOCK_USER_ID": "109754742613069927799", + "MOCK_USER_NAME": "Nikola Derežić" + }, "runtimeArgs": [ "run", // this is `run` from `npm run` "dev" // this is `dev` from `npm run dev` diff --git a/app/lib/auth.ts b/app/lib/auth.ts index b63a207..63e1fd2 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -1,39 +1,25 @@ import NextAuth, { NextAuthConfig } from 'next-auth'; import GoogleProvider from 'next-auth/providers/google'; -import LinkedinProvider from 'next-auth/providers/linkedin'; +// import LinkedinProvider from 'next-auth/providers/linkedin'; import { Session } from 'next-auth'; import { AuthenticatedUser } from './types/next-auth'; import { defaultLocale } from '../i18n'; export const myAuth = () => { + // Use mock authentication in development when enabled via environment variable + if (process.env.NODE_ENV === 'development' && process.env.USE_MOCK_AUTH === 'true') { + const session: Session = { + user: { + id: process.env.MOCK_USER_ID || "109754742613069927799", + name: process.env.MOCK_USER_NAME || "Nikola Derežić", + }, + expires: "123", + }; + + return Promise.resolve(session); + } - /** - - Google auth does not work in development environment - - this is a hack to make it work in development environment - - it returns a fake session object which is used by the Next-Auth middleware - - Instructions: when in dev environment, uncomment the following code snippet - - this will return a fake session object which is used by the Next-Auth middleware - - when in production environment, comment the code snippet back - - Note: this is not a secure way to handle authentication, it is only for development purposes - - in production environment, the auth should be handled by the Next-Auth middleware - - Code snippet: - - const session:Session = { - user: { - id: "109754742613069927799", - name: "Nikola Derežić", - }, - expires: "123", - }; - - return(Promise.resolve(session)); - */ - - return(auth()); + return auth(); } export const authConfig: NextAuthConfig = {