mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Add single-user authentication system with Better Auth integration (#76)
* Add Better Auth integration with session management - Implement user authentication using Better Auth library - Add login, register, and sign out functionality - Support passkey/WebAuthn authentication - Create database schema for users, sessions, accounts, passkeys - Add AuthProvider context and ProtectedRoute components - Add account settings page in settings dialog - Protect all API routes with authentication middleware - Update environment configuration for auth providers * Add single-user authentication system with admin setup - Add first-run Setup page for initial admin account creation - Add environment-based admin configuration (ADMIN_EMAIL, ADMIN_PASSWORD) - Add password reset capability via ADMIN_PASSWORD_RESET environment flag - Migrate to data routers with auth loaders, remove ProtectedRoute - Add change password functionality to account settings - Enforce AUTH_SECRET requirement in production - Auto-disable registration when admin is pre-configured via environment * Track busy/idle session status across hooks * Bump version to 0.7.5 * Update pnpm to 10.28.1
This commit is contained in:
1 parent
af292758c3
commit
81a66d2ddb
29 files changed
+2324
-149
No files matched your search
@@ -48,11 +48,83 @@ export function initializeDatabase(dbPath: string = './data/opencode.db'): Datab
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_opencode_user_id ON opencode_configs(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_opencode_default ON opencode_configs(user_id, is_default);
|
||||
|
||||
-- Better Auth tables
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
emailVerified INTEGER NOT NULL DEFAULT 0,
|
||||
image TEXT,
|
||||
createdAt INTEGER NOT NULL,
|
||||
updatedAt INTEGER NOT NULL,
|
||||
role TEXT DEFAULT 'user'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "session" (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
expiresAt INTEGER NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
createdAt INTEGER NOT NULL,
|
||||
updatedAt INTEGER NOT NULL,
|
||||
ipAddress TEXT,
|
||||
userAgent TEXT,
|
||||
userId TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_session_userId ON "session"(userId);
|
||||
CREATE INDEX IF NOT EXISTS idx_session_token ON "session"(token);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "account" (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
accountId TEXT NOT NULL,
|
||||
providerId TEXT NOT NULL,
|
||||
userId TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||
accessToken TEXT,
|
||||
refreshToken TEXT,
|
||||
idToken TEXT,
|
||||
accessTokenExpiresAt INTEGER,
|
||||
refreshTokenExpiresAt INTEGER,
|
||||
scope TEXT,
|
||||
password TEXT,
|
||||
createdAt INTEGER NOT NULL,
|
||||
updatedAt INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_account_userId ON "account"(userId);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_account_provider ON "account"(providerId, accountId);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "verification" (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
identifier TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
expiresAt INTEGER NOT NULL,
|
||||
createdAt INTEGER,
|
||||
updatedAt INTEGER
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_verification_identifier ON "verification"(identifier);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "passkey" (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
name TEXT,
|
||||
publicKey TEXT NOT NULL,
|
||||
userId TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||
credentialID TEXT NOT NULL,
|
||||
counter INTEGER NOT NULL,
|
||||
deviceType TEXT NOT NULL,
|
||||
backedUp INTEGER NOT NULL DEFAULT 0,
|
||||
transports TEXT,
|
||||
createdAt INTEGER,
|
||||
aaguid TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_passkey_userId ON "passkey"(userId);
|
||||
CREATE INDEX IF NOT EXISTS idx_passkey_credentialID ON "passkey"(credentialID);
|
||||
`)
|
||||
|
||||
runMigrations(db)
|
||||
|
||||
// Force database file creation by performing a write
|
||||
db.prepare('INSERT OR IGNORE INTO user_preferences (user_id, preferences, updated_at) VALUES (?, ?, ?)')
|
||||
.run('default', '{}', Date.now())
|
||||
|
||||
|
||||
Reference in new issue
Block a user