improve development authentication setup
- 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 <noreply@anthropic.com>
This commit is contained in:
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@@ -9,6 +9,11 @@
|
|||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"envFile": "${workspaceFolder}/.env",
|
"envFile": "${workspaceFolder}/.env",
|
||||||
|
"env": {
|
||||||
|
"USE_MOCK_AUTH": "true",
|
||||||
|
"MOCK_USER_ID": "109754742613069927799",
|
||||||
|
"MOCK_USER_NAME": "Nikola Derežić"
|
||||||
|
},
|
||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"run", // this is `run` from `npm run`
|
"run", // this is `run` from `npm run`
|
||||||
"dev" // this is `dev` from `npm run dev`
|
"dev" // this is `dev` from `npm run dev`
|
||||||
|
|||||||
@@ -1,39 +1,25 @@
|
|||||||
import NextAuth, { NextAuthConfig } from 'next-auth';
|
import NextAuth, { NextAuthConfig } from 'next-auth';
|
||||||
import GoogleProvider from 'next-auth/providers/google';
|
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 { Session } from 'next-auth';
|
||||||
import { AuthenticatedUser } from './types/next-auth';
|
import { AuthenticatedUser } from './types/next-auth';
|
||||||
import { defaultLocale } from '../i18n';
|
import { defaultLocale } from '../i18n';
|
||||||
|
|
||||||
export const myAuth = () => {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return auth();
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authConfig: NextAuthConfig = {
|
export const authConfig: NextAuthConfig = {
|
||||||
|
|||||||
Reference in New Issue
Block a user