From 2cf338c50aad14eb6b51437b7d87c920997ef1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 10:47:55 +0200 Subject: [PATCH] improve development authentication setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced manual code commenting with environment variable controlled mock auth - Added development env vars to VS Code launch.json for automatic mock authentication - Removed unused LinkedIn provider import - Authentication now automatically uses mock session when launched via VS Code debug - Zero security impact on production (env vars only exist during debug sessions) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .vscode/launch.json | 5 +++++ app/lib/auth.ts | 42 ++++++++++++++---------------------------- 2 files changed, 19 insertions(+), 28 deletions(-) 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 = {