Skip to content

Commit 971bf93

Browse files
committed
refactor(dashboard): Reduce the platform dashboard to authentication.
1 parent 5d90c80 commit 971bf93

12 files changed

Lines changed: 45 additions & 1050 deletions

File tree

‎platform/packages/dashboard/README.md‎

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
# @voidcloud/dashboard
22

3-
User-facing dashboard for Void. Built as a React Pages mode app, dogfooding the
4-
platform.
3+
Authentication frontend for the Void platform. Built as a React Pages mode app,
4+
dogfooding the platform.
55

66
## Architecture
77

88
- **React Pages mode** - `voidPlugin()` + `voidReact()`, SSR with client hydration.
9-
- **API-only data access** - loaders and actions call the platform API. The dashboard
10-
does not connect to platform Postgres directly.
119
- **Auth** - OAuth (GitHub/Google) via the platform's `/auth/login` flow. The JWT is
1210
stored in an httpOnly cookie (`void_token`). Middleware validates the token with
1311
`GET /me`.
14-
- **Preview gate** - authenticated non-admin users see a gated page while the
15-
dashboard is rebuilt. Admin users can access the dashboard routes.
1612
- **Styling** - Tailwind CSS v4 with the Void design system from `@voidcloud/ui`
1713
(VoidZero theme styles, fonts, assets, and React UI primitives).
1814

1915
## Pages
2016

21-
| Route | Purpose |
22-
| --------------- | ----------------------------------------------- |
23-
| `/login` | OAuth buttons (GitHub, Google) |
24-
| `/` | Admin-gated project list |
25-
| `/projects/:id` | Deployments, usage, domains, secrets, resources |
26-
| `/settings` | Profile |
27-
| `/logout` | Clears cookie, redirects to login |
17+
| Route | Purpose |
18+
| ---------------- | ---------------------------------------- |
19+
| `/login` | OAuth buttons (GitHub, Google) |
20+
| `/auth/callback` | Exchanges the login response for a token |
21+
| `/` | Minimal authenticated confirmation page |
22+
| `/logout` | Clears cookie, redirects to login |
2823

2924
## Local Development
3025

@@ -71,23 +66,18 @@ on the dashboard side, so it never activates in production.
7166

7267
```text
7368
lib/
74-
api.ts # Typed platform API client + fetch helpers
69+
api.ts # Typed authentication API fetch helpers
7570
middleware/
76-
01.auth.ts # void_token validation through /me + admin preview gate
71+
01.auth.ts # void_token validation through /me
7772
pages/
78-
layout.tsx # Top bar with nav + user info
73+
layout.tsx # Authenticated shell with logout
7974
login.tsx # OAuth login buttons
8075
login.server.ts # Builds provider login URLs
8176
logout.tsx
8277
logout.server.ts # Cookie clear + redirect
83-
index.tsx # Project list or preview gate
84-
index.server.ts # API reads for projects
85-
settings.tsx # Profile
86-
settings.server.ts # Session user from middleware
78+
index.tsx # Authenticated confirmation page
79+
index.server.ts # Session user from middleware
8780
auth/
8881
callback.tsx
8982
callback.server.ts # OAuth callback token/code exchange
90-
projects/
91-
[id].tsx # Project detail
92-
[id].server.ts # API reads/actions for project dashboard data
9383
```

‎platform/packages/dashboard/lib/api.ts‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ export function getPublicApiUrl(context: Context): string {
101101
return getApiUrl(context);
102102
}
103103

104-
export function getApiOrigin(context: Context): string {
105-
return new URL(getApiUrl(context)).origin;
106-
}
107-
108-
export function getApiClientFetch(context: Context): typeof fetch {
109-
return getApiFetch(context);
110-
}
111-
112104
export async function fetchApi(
113105
context: Context,
114106
path: string,
@@ -125,21 +117,6 @@ export async function fetchApi(
125117
});
126118
}
127119

128-
/** Use service binding when available (production), fall back to HTTP (local dev). */
129-
export function createClient(context: Context) {
130-
const token = getToken(context);
131-
const baseUrl = getApiUrl(context);
132-
const headers = getCfAccessHeaders(context);
133-
headers.Accept = 'application/json';
134-
if (token) {
135-
headers.Authorization = `Bearer ${token}`;
136-
}
137-
return hc<ApiRoutes>(baseUrl, {
138-
fetch: getTimedApiFetch(context),
139-
headers,
140-
});
141-
}
142-
143120
export async function getApiErrorMessage(res: ApiResponse): Promise<string> {
144121
const body = await res.text();
145122
if (!body) {
@@ -199,24 +176,3 @@ export async function getCurrentUser(context: Context): Promise<API<'me'> | null
199176
}
200177
return readApiJson<API<'me'>>(res);
201178
}
202-
203-
export class ApiError extends Error {
204-
constructor(
205-
public readonly status: number,
206-
message: string,
207-
) {
208-
super(message);
209-
}
210-
}
211-
212-
export async function api(
213-
context: Context,
214-
path: string,
215-
options?: RequestInit,
216-
): Promise<Response> {
217-
const res = await fetchApi(context, path, options);
218-
if (!res.ok) {
219-
throw new ApiError(res.status, await getApiErrorMessage(res));
220-
}
221-
return res;
222-
}

‎platform/packages/dashboard/middleware/01.auth.ts‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ export type DashboardUser = API<'me'>;
66

77
export type DashboardShared = Readonly<{
88
user: DashboardUser | null;
9-
canAccessDashboard: boolean;
109
}>;
1110

1211
declare module 'void' {
1312
interface CloudContextVariables {
1413
token: string;
15-
userId: string;
1614
dashboardUser: DashboardUser;
17-
canAccessDashboard: boolean;
1815
shared: DashboardShared;
1916
}
2017
}
@@ -26,42 +23,30 @@ export function isPublicDashboardPath(path: string): boolean {
2623
return PUBLIC_PATHS.has(path) || PUBLIC_PREFIXES.some((prefix) => path.startsWith(prefix));
2724
}
2825

29-
function isLocalHost(host: string | undefined): boolean {
30-
host ??= '';
31-
return host.startsWith('localhost') || host.startsWith('127.0.0.1');
32-
}
33-
3426
export default defineMiddleware(async (context, next) => {
3527
const path = context.req.path;
3628

3729
if (isPublicDashboardPath(path)) {
38-
context.set('shared', { user: null, canAccessDashboard: false });
30+
context.set('shared', { user: null });
3931
return next();
4032
}
4133

4234
const token = getCookie(context, 'void_token');
4335
if (!token) {
44-
context.set('shared', { user: null, canAccessDashboard: false });
36+
context.set('shared', { user: null });
4537
return context.redirect('/login');
4638
}
4739

4840
context.set('token', token);
4941
const user = await getCurrentUser(context);
5042
if (!user) {
5143
deleteCookie(context, 'void_token', { path: '/' });
52-
context.set('shared', { user: null, canAccessDashboard: false });
44+
context.set('shared', { user: null });
5345
return context.redirect('/login');
5446
}
5547

56-
const canAccessDashboard = user.role === 'admin' || isLocalHost(context.req.header('host'));
57-
context.set('userId', user.id);
5848
context.set('dashboardUser', user);
59-
context.set('canAccessDashboard', canAccessDashboard);
60-
context.set('shared', { user, canAccessDashboard });
61-
62-
if (!canAccessDashboard && path !== '/') {
63-
return context.redirect('/');
64-
}
49+
context.set('shared', { user });
6550

6651
return next();
6752
});
Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
import { defineHandler } from 'void';
2-
import { createClient, readApiJson, type API } from '../lib/api.ts';
2+
import type { API } from '../lib/api.ts';
33

4-
export type Props =
5-
| {
6-
canAccessDashboard: false;
7-
user: API<'me'>;
8-
}
9-
| {
10-
canAccessDashboard: true;
11-
user: API<'me'>;
12-
projects: API<'projects'>;
13-
siteDomain: string;
14-
};
4+
export type Props = Readonly<{
5+
user: API<'me'>;
6+
}>;
157

16-
export const loader = defineHandler<Props>(async (context) => {
17-
const user = context.get('dashboardUser');
18-
if (!context.get('canAccessDashboard')) {
19-
return { canAccessDashboard: false, user };
20-
}
21-
22-
const client = createClient(context);
23-
let projects: API<'projects'> = [];
24-
try {
25-
const projectsRes = await client.projects.$get();
26-
projects = projectsRes.ok ? ((await readApiJson<API<'projects'>>(projectsRes)) ?? []) : [];
27-
} catch (error) {
28-
console.warn(
29-
`[dashboard] /projects request failed: ${error instanceof Error ? error.message : String(error)}`,
30-
);
31-
}
32-
const siteDomain = (context.env as Record<string, string>).SITE_DOMAIN ?? 'void.app';
33-
34-
return {
35-
canAccessDashboard: true,
36-
user,
37-
projects,
38-
siteDomain,
39-
};
40-
});
8+
export const loader = defineHandler<Props>((context) => ({
9+
user: context.get('dashboardUser'),
10+
}));

0 commit comments

Comments
 (0)