Skip to content

Commit 0aebf19

Browse files
committed
Integrate organization management with better-auth
Replaced custom auth client with better-auth, updated API routes to /api/v6/auth, and added organization management UI and logic. Users can now create, switch, and manage organizations and members. Updated navigation and context to support organization-aware sessions. Adjusted Vite proxy target for API.
1 parent d8b242f commit 0aebf19

File tree

14 files changed

+538
-66
lines changed

14 files changed

+538
-66
lines changed

package-lock.json

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/auth/auth.client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const getAuth = async () => {
1414
});
1515
authInstance = betterAuth({
1616
database: pool,
17-
trustedOrigins: ["http://localhost:5173", "http://localhost:3000"],
17+
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3100/api/v6/auth",
18+
trustedOrigins: ["http://localhost:5173", "http://localhost:3000", "http://localhost:3100"],
1819
emailAndPassword: {
1920
enabled: true
2021
},
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { Controller, All, Req, Res } from '@nestjs/common';
22
import { getAuth } from './auth.client';
33

4-
@Controller('api/auth')
4+
@Controller('api/v6/auth')
55
export class AuthController {
66
@All('*')
77
async handleAuth(@Req() req, @Res() res) {
8-
const auth = await getAuth();
9-
const { toNodeHandler } = await import('better-auth/node');
10-
return toNodeHandler(auth)(req, res);
8+
try {
9+
const auth = await getAuth();
10+
const { toNodeHandler } = await import('better-auth/node');
11+
return toNodeHandler(auth)(req, res);
12+
} catch (error) {
13+
console.error('Auth Error:', error);
14+
res.status(500).json({ error: 'Internal Server Error', details: error.message });
15+
}
1116
}
1217
}

packages/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@objectql/ui": "*",
15+
"better-auth": "^1.4.10",
1516
"clsx": "^2.1.0",
1617
"lucide-react": "^0.344.0",
1718
"react": "^18.3.1",

packages/client/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
22
import Login from './pages/Login';
33
import Dashboard from './pages/Dashboard';
44
import Settings from './pages/Settings';
5+
import Organization from './pages/Organization';
56
import { AuthProvider, useAuth } from './context/AuthContext';
67
import { AppSidebar } from './components/app-sidebar';
78
import { SidebarProvider, SidebarInset, SidebarTrigger, Separator, Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from '@objectql/ui';
@@ -90,7 +91,8 @@ function AppContent() {
9091
</Breadcrumb>
9192
</header>
9293
<div className="flex flex-1 flex-col gap-4 p-4">
93-
{currentPath === '/settings' ? <Settings /> : <Dashboard />}
94+
{currentPath === '/settings' ? <Settings /> :
95+
currentPath === '/organization' ? <Organization /> : <Dashboard />}
9496
</div>
9597
</SidebarInset>
9698
</SidebarProvider>

packages/client/src/components/nav-user.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,19 @@ export function NavUser({
7878
</DropdownMenuLabel>
7979
<DropdownMenuSeparator />
8080
<DropdownMenuGroup>
81-
<DropdownMenuItem>
81+
<DropdownMenuItem onClick={() => {
82+
window.history.pushState({}, '', '/settings');
83+
window.dispatchEvent(new Event('pushstate'));
84+
}}>
8285
<BadgeCheck className="mr-2 h-4 w-4" />
8386
Account
8487
</DropdownMenuItem>
85-
<DropdownMenuItem>
88+
<DropdownMenuItem onClick={() => {
89+
window.history.pushState({}, '', '/organization');
90+
window.dispatchEvent(new Event('pushstate'));
91+
}}>
8692
<CreditCard className="mr-2 h-4 w-4" />
87-
Billing
93+
Organization
8894
</DropdownMenuItem>
8995
<DropdownMenuItem>
9096
<Bell className="mr-2 h-4 w-4" />

0 commit comments

Comments
 (0)