mirror of
https://github.com/tale/headplane.git
synced 2026-08-29 08:27:08 +00:00
feat: respect context in server
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Building2, House, Key } from 'lucide-react';
|
||||
import Card from '~/components/Card';
|
||||
import Link from '~/components/Link';
|
||||
import { HeadplaneConfig } from '~/utils/state';
|
||||
import type { AppContext } from '~server/context/app';
|
||||
import CreateUser from '../dialogs/create-user';
|
||||
|
||||
interface Props {
|
||||
oidc?: NonNullable<HeadplaneConfig['oidc']>;
|
||||
oidc?: NonNullable<AppContext['context']['oidc']>;
|
||||
}
|
||||
|
||||
export default function ManageBanner({ oidc }: Props) {
|
||||
|
||||
@@ -14,14 +14,22 @@ import cn from '~/utils/cn';
|
||||
import { pull } from '~/utils/headscale';
|
||||
import { getSession } from '~/utils/sessions.server';
|
||||
|
||||
import { hp_getConfig, hs_getConfig } from '~/utils/state';
|
||||
import { hs_getConfig } from '~/utils/config/loader';
|
||||
import { noContext } from '~/utils/log';
|
||||
import type { AppContext } from '~server/context/app';
|
||||
import ManageBanner from './components/manage-banner';
|
||||
import DeleteUser from './dialogs/delete-user';
|
||||
import RenameUser from './dialogs/rename-user';
|
||||
import { userAction } from './user-actions';
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
export async function loader({
|
||||
request,
|
||||
context,
|
||||
}: LoaderFunctionArgs<AppContext>) {
|
||||
const session = await getSession(request.headers.get('Cookie'));
|
||||
if (!context) {
|
||||
throw noContext();
|
||||
}
|
||||
|
||||
const [machines, apiUsers] = await Promise.all([
|
||||
pull<{ nodes: Machine[] }>('v1/node', session.get('hsApiKey')!),
|
||||
@@ -33,7 +41,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
machines: machines.nodes.filter((machine) => machine.user.id === user.id),
|
||||
}));
|
||||
|
||||
const context = hp_getConfig();
|
||||
const ctx = context.context;
|
||||
const { mode, config } = hs_getConfig();
|
||||
let magic: string | undefined;
|
||||
|
||||
@@ -44,7 +52,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
}
|
||||
|
||||
return {
|
||||
oidc: context.oidc,
|
||||
oidc: ctx.oidc,
|
||||
magic,
|
||||
users,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user