Skip to content

Commit 5f8a06a

Browse files
committed
Migrate better-auth to platform package and update roles
Renamed and moved the @objectql/better-auth package to @objectql/platform, including all object definitions and configuration. Added platform-level role definitions (super_admin, admin, user) and updated server and client code to reference the new package and roles. Refactored client layout to support a settings page and improved sidebar/object routing. Removed the old better-auth README and added a new README for the platform package.
1 parent 7d7671b commit 5f8a06a

26 files changed

+297
-336
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: user
2+
label: User
3+
description: Standard User Role
4+
policies:
5+
- base_access
6+
7+
permissions:
8+
tasks:
9+
# Additive: Can also UPDATE own tasks
10+
actions: [update]
11+
filters:
12+
- ['assigned_to', '=', '$user.id']

package-lock.json

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

packages/better-auth/README.md

Lines changed: 0 additions & 201 deletions
This file was deleted.

packages/client/src/App.tsx

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
11
import { useState, useEffect } from 'react';
22
import Login from './pages/Login';
33
import Dashboard from './pages/Dashboard';
4+
import Settings from './pages/Settings';
45
import { AuthProvider, useAuth } from './context/AuthContext';
6+
import { AppSidebar } from './components/app-sidebar';
7+
import { SidebarProvider, SidebarInset, SidebarTrigger, Separator, Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from '@objectql/ui';
58

69
function AppContent() {
710
const { user, loading } = useAuth();
811
const [currentPath, setCurrentPath] = useState(window.location.pathname);
12+
// This would ideally come from a context or prop passed from Dashboard,
13+
// but for now we'll fetch objects to pass to Sidebar in AppContent as well if needed,
14+
// or refactor layout.
15+
// ACTUALLY: Dashboard handles the Sidebar usually.
16+
// Let's modify AppContent to render the Main Layout if logged in.
17+
18+
const [objects, setObjects] = useState<Record<string, any>>({});
19+
20+
// We need to fetch objects for the sidebar if we are not in dashboard
21+
useEffect(() => {
22+
if (user && Object.keys(objects).length === 0) {
23+
fetch('/api/v6/metadata/object')
24+
.then(res => res.json())
25+
.then(result => {
26+
const objectsMap: Record<string, any> = {};
27+
if (Array.isArray(result)) {
28+
result.forEach((obj: any) => {
29+
objectsMap[obj.name] = obj;
30+
});
31+
}
32+
setObjects(objectsMap);
33+
})
34+
.catch(console.error);
35+
}
36+
}, [user]);
937

1038
useEffect(() => {
1139
const handlePopState = () => setCurrentPath(window.location.pathname);
1240
window.addEventListener('popstate', handlePopState);
13-
return () => window.removeEventListener('popstate', handlePopState);
41+
42+
// Custom event for navigation
43+
const handlePushState = () => setCurrentPath(window.location.pathname);
44+
window.addEventListener('pushstate', handlePushState);
45+
46+
return () => {
47+
window.removeEventListener('popstate', handlePopState);
48+
window.removeEventListener('pushstate', handlePushState);
49+
};
1450
}, []);
1551

1652
if (loading) {
@@ -21,25 +57,44 @@ function AppContent() {
2157
);
2258
}
2359

24-
// Simple routing
25-
if (!user && currentPath !== '/login') {
26-
window.history.pushState({}, '', '/login');
27-
// Update state to match new URL to prevent inconsistent state
60+
// Auth Routing
61+
if (!user) {
2862
if (currentPath !== '/login') {
29-
setCurrentPath('/login');
63+
window.history.pushState({}, '', '/login');
64+
return <Login />;
3065
}
3166
return <Login />;
3267
}
3368

3469
if (currentPath === '/login') {
35-
if (user) {
36-
window.history.pushState({}, '', '/dashboard');
37-
return <Dashboard />;
38-
}
39-
return <Login />;
70+
window.history.pushState({}, '', '/');
71+
setCurrentPath('/');
4072
}
4173

42-
return <Dashboard />;
74+
// Main Layout
75+
return (
76+
<SidebarProvider>
77+
<AppSidebar objects={objects} />
78+
<SidebarInset>
79+
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
80+
<SidebarTrigger className="-ml-1" />
81+
<Separator orientation="vertical" className="mr-2 h-4" />
82+
<Breadcrumb>
83+
<BreadcrumbList>
84+
<BreadcrumbItem>
85+
<BreadcrumbPage>
86+
{currentPath === '/settings' ? 'Settings' : 'Dashboard'}
87+
</BreadcrumbPage>
88+
</BreadcrumbItem>
89+
</BreadcrumbList>
90+
</Breadcrumb>
91+
</header>
92+
<div className="flex flex-1 flex-col gap-4 p-4">
93+
{currentPath === '/settings' ? <Settings /> : <Dashboard />}
94+
</div>
95+
</SidebarInset>
96+
</SidebarProvider>
97+
);
4398
}
4499

45100
function App() {
@@ -51,3 +106,4 @@ function App() {
51106
}
52107

53108
export default App;
109+

0 commit comments

Comments
 (0)