|
36 | 36 |
|
37 | 37 | async function init() { |
38 | 38 | await reloadServerInfo() |
39 | | - if (!get(serverInfo)?.username) { |
| 39 | + const adminPermissions = get(serverInfo)?.adminPermissions |
| 40 | + if ( |
| 41 | + !get(serverInfo)?.username || |
| 42 | + !adminPermissions || |
| 43 | + !ADMIN_PERMISSIONS.some(p => adminPermissions[p.key]) |
| 44 | + ) { |
40 | 45 | // Not logged in: redirect to the (gateway) login page, preserving this admin |
41 | 46 | // URL — hash route included — as `next` so we return exactly here afterwards. |
42 | 47 | // (The admin shell is no longer server-gated, so this runs client-side where |
|
45 | 50 | location.assign( |
46 | 51 | `/@warpgate#/login?next=${encodeURIComponent(next)}`, |
47 | 52 | ) |
| 53 | + await new Promise(() => undefined) |
48 | 54 | } |
49 | 55 | } |
50 | 56 |
|
51 | 57 | const initPromise = init() |
52 | 58 |
|
53 | | - async function requireAdmin(detail: RouteDetail) { |
54 | | - await initPromise |
55 | | - const adminPermissions = get(serverInfo)?.adminPermissions |
56 | | - if ( |
57 | | - !adminPermissions || |
58 | | - !ADMIN_PERMISSIONS.some(p => adminPermissions[p.key]) |
59 | | - ) { |
60 | | - let url = `${location.pathname}#${detail.location}` |
61 | | - if (detail.querystring) { |
62 | | - url += `?${detail.querystring}` |
63 | | - } |
64 | | - push(`/login?next=${encodeURIComponent(url)}`) |
65 | | - return false |
66 | | - } |
67 | | - return true |
68 | | - } |
69 | | -
|
70 | 59 | const routes: Record<string, WrappedComponent> = { |
71 | 60 | '/': wrap({ |
72 | 61 | component: Redirect, |
73 | 62 | props: { to: '/status/sessions' }, |
74 | | - conditions: [requireAdmin], |
75 | 63 | }), |
76 | 64 | '/status/recordings/:id': wrap({ |
77 | 65 | asyncComponent: () => import('./status/Recording.svelte'), |
78 | | - conditions: [requireAdmin], |
79 | 66 | }), |
80 | 67 | '/status': wrap({ |
81 | 68 | asyncComponent: () => import('./status/Status.svelte'), |
82 | | - conditions: [requireAdmin], |
83 | 69 | }), |
84 | 70 | '/log': wrap({ |
85 | 71 | asyncComponent: () => import('./Log.svelte'), |
86 | | - conditions: [requireAdmin], |
87 | 72 | }), |
88 | 73 | '/log/user/:id': wrap({ |
89 | 74 | asyncComponent: () => import('./Log.svelte'), |
90 | 75 | props: { |
91 | 76 | filterKind: 'user', |
92 | 77 | }, |
93 | | - conditions: [requireAdmin], |
94 | 78 | }), |
95 | 79 | '/log/access-role/:id': wrap({ |
96 | 80 | asyncComponent: () => import('./Log.svelte'), |
97 | 81 | props: { |
98 | 82 | filterKind: 'access-role', |
99 | 83 | }, |
100 | | - conditions: [requireAdmin], |
101 | 84 | }), |
102 | 85 | '/log/admin-role/:id': wrap({ |
103 | 86 | asyncComponent: () => import('./Log.svelte'), |
104 | 87 | props: { |
105 | 88 | filterKind: 'admin-role', |
106 | 89 | }, |
107 | | - conditions: [requireAdmin], |
108 | 90 | }), |
109 | 91 | '/config': wrap({ |
110 | 92 | asyncComponent: () => import('./config/Config.svelte'), |
111 | | - conditions: [requireAdmin], |
112 | 93 | }), |
113 | 94 | } |
114 | 95 | // biome-ignore lint/style/noNonNullAssertion: x |
|
0 commit comments