Skip to content

Commit feecd20

Browse files
shantanu patilclaude
authored andcommitted
Add GitHub + Google OAuth login with encrypted API key storage
Implement NextAuth.js v5 authentication with GitHub and Google OAuth providers, backed by Drizzle ORM adapter storing users/accounts in the existing PostgreSQL database. Logged-in users can save their Anthropic API key and GitHub PAT encrypted (AES-256-GCM) in the database instead of localStorage, so keys persist across devices and sessions. Non-logged-in users retain the existing localStorage flow unchanged. - Add users, accounts, sessions, verification_tokens tables to schema - Create auth config with JWT session strategy and Drizzle adapter - Add AES-256-GCM encryption utilities for API key storage - Add server actions for saving/loading/clearing encrypted keys - Add Sign In button with avatar dropdown in header - Update API key and Private Repos dialogs for dual-mode storage - Update useDiagram hook to prefer DB-stored keys when logged in - Add identity rewrite in next.config.js to prevent /api/auth/* proxying - Add SessionProvider to app providers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5b8e017 commit feecd20

18 files changed

Lines changed: 1294 additions & 46 deletions

File tree

diagrams/.env.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ NEXT_PUBLIC_API_DEV_URL=http://localhost:8000
1111

1212
# Skip env validation during build (useful for Docker/CI)
1313
# SKIP_ENV_VALIDATION=1
14+
15+
# ── Authentication (NextAuth.js v5) ──
16+
17+
# Required: Random secret for JWT signing (openssl rand -base64 32)
18+
# AUTH_SECRET=your-secret-here
19+
20+
# GitHub OAuth App credentials (github.com/settings/developers)
21+
# AUTH_GITHUB_ID=your-github-client-id
22+
# AUTH_GITHUB_SECRET=your-github-client-secret
23+
24+
# Google OAuth credentials (console.cloud.google.com > APIs & Services > Credentials)
25+
# AUTH_GOOGLE_ID=your-google-client-id
26+
# AUTH_GOOGLE_SECRET=your-google-client-secret
27+
28+
# Encryption key for API keys stored in DB (openssl rand -hex 32)
29+
# ENCRYPTION_KEY=64-hex-characters-here

diagrams/next.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ const config = {
2525
destination: "https://us.i.posthog.com/decide",
2626
},
2727
],
28-
// Proxy /api/* to GitUnderstand backend
28+
// Proxy /api/* to GitUnderstand backend (excluding /api/auth/* which is handled by NextAuth)
2929
afterFiles: [
30+
{
31+
source: "/api/auth/:path*",
32+
destination: "/api/auth/:path*",
33+
},
3034
{
3135
source: "/api/:path*",
3236
destination: `${process.env.GITUNDERSTAND_API_URL ?? "http://localhost:8080"}/api/:path*`,

diagrams/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"test:smoke": "python -m pytest tests/ -v -m smoke"
2424
},
2525
"dependencies": {
26+
"@auth/drizzle-adapter": "^1.11.1",
2627
"@neondatabase/serverless": "^0.10.4",
2728
"@radix-ui/react-dialog": "^1.1.4",
29+
"@radix-ui/react-dropdown-menu": "^2.1.16",
2830
"@radix-ui/react-progress": "^1.1.1",
2931
"@radix-ui/react-slot": "^1.1.1",
3032
"@radix-ui/react-switch": "^1.1.3",
@@ -39,6 +41,7 @@
3941
"lucide-react": "^0.468.0",
4042
"mermaid": "^11.4.1",
4143
"next": "^15.0.1",
44+
"next-auth": "5.0.0-beta.30",
4245
"next-themes": "^0.4.6",
4346
"postgres": "^3.4.4",
4447
"posthog-js": "^1.203.1",

0 commit comments

Comments
 (0)