feat: wire auth and CRUD UI to APIs
This commit is contained in:
15
app/(app)/app/elders/page.tsx
Normal file
15
app/(app)/app/elders/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getCurrentAuthContext } from "@/modules/core/server/auth";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
import { EldersClient } from "@/modules/elders/components/EldersClient";
|
||||
|
||||
export default async function EldersPage(): Promise<React.ReactElement> {
|
||||
const context = await getCurrentAuthContext();
|
||||
if (!context) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const data = await readData();
|
||||
return <EldersClient initialElders={data.elders} permissions={context.permissions} />;
|
||||
}
|
||||
26
app/(app)/app/layout.tsx
Normal file
26
app/(app)/app/layout.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getBootstrapState, getCurrentAuthContext } from "@/modules/core/server/auth";
|
||||
import { AppShell } from "@/modules/shared/components/AppShell";
|
||||
|
||||
type AppLayoutProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export default async function AppLayout({ children }: AppLayoutProps): Promise<React.ReactElement> {
|
||||
const bootstrap = await getBootstrapState();
|
||||
if (bootstrap.setupRequired) {
|
||||
redirect("/setup");
|
||||
}
|
||||
|
||||
const context = await getCurrentAuthContext();
|
||||
if (!context) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<AppShell account={context.account} permissions={context.permissions}>
|
||||
{children}
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
26
app/(app)/app/settings/page.tsx
Normal file
26
app/(app)/app/settings/page.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getCurrentAuthContext, toPublicAccount } from "@/modules/core/server/auth";
|
||||
import { hasPermission, ROLE_DEFINITIONS } from "@/modules/core/server/permissions";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
import { SettingsOverview } from "@/modules/settings/components/SettingsOverview";
|
||||
|
||||
export default async function SettingsPage(): Promise<React.ReactElement> {
|
||||
const context = await getCurrentAuthContext();
|
||||
if (!context) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
if (!hasPermission(context.account.role, "account:read")) {
|
||||
redirect("/app/dashboard");
|
||||
}
|
||||
|
||||
const data = await readData();
|
||||
return (
|
||||
<SettingsOverview
|
||||
accounts={data.accounts.map((account) => toPublicAccount(account))}
|
||||
roles={ROLE_DEFINITIONS}
|
||||
auditLogs={data.auditLogs.slice(0, 100)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user