Skip to content

Commit 2ffab76

Browse files
Copilothotlong
andcommitted
fix: address code review feedback for auth-manager security and configuration
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 45391da commit 2ffab76

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

packages/plugins/plugin-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"vitest": "^4.0.18"
2121
},
2222
"peerDependencies": {
23-
"drizzle-orm": ">=0.41.0"
23+
"drizzle-orm": "^0.41.0"
2424
},
2525
"peerDependenciesMeta": {
2626
"drizzle-orm": {

packages/plugins/plugin-auth/src/auth-manager.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,10 @@ export class AuthManager {
6161
secret: this.config.secret || this.generateSecret(),
6262
baseURL: this.config.baseUrl || 'http://localhost:3000',
6363

64-
// Database adapter - use memory for now
65-
// In production, use appropriate database adapter
66-
database: {
67-
// Using in-memory adapter for development
68-
// @TODO: Implement proper database adapter
69-
adapter: 'better-sqlite3' as any,
70-
} as any,
64+
// Database adapter configuration
65+
// For now, we configure a basic setup that will be enhanced
66+
// when database URL is provided and drizzle-orm is available
67+
database: this.createDatabaseConfig(),
7168

7269
// Email configuration
7370
emailAndPassword: {
@@ -84,13 +81,50 @@ export class AuthManager {
8481
return betterAuth(betterAuthConfig);
8582
}
8683

84+
/**
85+
* Create database configuration
86+
* TODO: Implement proper database adapter when drizzle-orm is available
87+
*/
88+
private createDatabaseConfig(): any {
89+
// If databaseUrl is provided, we would use drizzle adapter
90+
// For now, this is a placeholder configuration
91+
if (this.config.databaseUrl) {
92+
console.warn(
93+
'Database URL provided but adapter integration not yet complete. ' +
94+
'Install drizzle-orm and configure a proper adapter for production use.'
95+
);
96+
}
97+
98+
// Return a minimal configuration that better-auth can work with
99+
// This will need to be replaced with a proper adapter
100+
return {
101+
// Placeholder - will be replaced with actual adapter
102+
adapter: 'in-memory' as any,
103+
};
104+
}
105+
87106
/**
88107
* Generate a secure secret if not provided
89108
*/
90109
private generateSecret(): string {
91-
// In production, this should come from environment variables
92-
// This is just a fallback for development
93-
return process.env.AUTH_SECRET || 'default-secret-change-in-production';
110+
const envSecret = process.env.AUTH_SECRET;
111+
112+
if (!envSecret) {
113+
// In production, a secret MUST be provided
114+
// For development/testing, we'll use a fallback but warn about it
115+
const fallbackSecret = 'dev-secret-' + Date.now();
116+
117+
console.warn(
118+
'⚠️ WARNING: No AUTH_SECRET environment variable set! ' +
119+
'Using a temporary development secret. ' +
120+
'This is NOT secure for production use. ' +
121+
'Please set AUTH_SECRET in your environment variables.'
122+
);
123+
124+
return fallbackSecret;
125+
}
126+
127+
return envSecret;
94128
}
95129

96130
/**

0 commit comments

Comments
 (0)