diff --git a/components/Page.tsx b/components/Page.tsx index 23e657e..cf9a0ec 100644 --- a/components/Page.tsx +++ b/components/Page.tsx @@ -1,11 +1,47 @@ import { JSX } from "preact"; +import { type PublicUser } from "@/types.ts"; const NAV_ITEM_CLASSES = "flex justify-center items-center px-4 py-2 hover:bg-gray-300 dark:hover:bg-gray-700"; const HEADER_CLASSES = "bg-gray-200 dark:bg-gray-800"; -export function Page(props: JSX.HTMLAttributes) { +export function LoginNavItems() { + return ( + <> + + Register + + Login + + ); +} + +export function UserNavItems() { + return ( + <> + + Profile + + Dashboard + Logout + + ); +} + +export interface PageProps extends JSX.HTMLAttributes { + user?: PublicUser; +} + +export function Page(props: PageProps) { return (
@@ -18,10 +54,7 @@ export function Page(props: JSX.HTMLAttributes) {

LyricScreen

Notes - - Register - - Login + {props.user ? UserNavItems() : LoginNavItems()}
diff --git a/log.ts b/log.ts index 2d34c45..6178e6a 100644 --- a/log.ts +++ b/log.ts @@ -1,6 +1,7 @@ -export * as log from "$std/log/mod.ts"; import * as log from "$std/log/mod.ts"; +export * as log from "$std/log/mod.ts"; + const levelColors = {}; export function setupLoggers() { diff --git a/routes/dashboard.tsx b/routes/dashboard.tsx index 301d01e..41c2934 100644 --- a/routes/dashboard.tsx +++ b/routes/dashboard.tsx @@ -1,13 +1,13 @@ -import { Handlers, PageProps } from "$fresh/server.ts"; import { Page } from "@/components/Page.tsx"; // import { getToken, getUser } from "@/db/mod.ts"; // import * as base64 from "$std/encoding/base64.ts"; +import { Handlers, PageProps } from "$fresh/server.ts"; import { type ContextState } from "@/types.ts"; export const handler: Handlers = { async GET(_request: Request, context) { const user: Partial = context.state.user; - delete user.passwordDigest; + if (user && "passwordDigest" in user) delete user.passwordDigest; return await context.render(context.state.user); }, }; diff --git a/types.ts b/types.ts index 8ca144f..7f714c4 100644 --- a/types.ts +++ b/types.ts @@ -22,6 +22,13 @@ export interface User extends Identifiable, Timestamped { displayName?: string; } +export type PublicUser = Pick< + User, + | "displayName" + | "username" + | keyof Identifiable +>; + export interface Note extends Identifiable, Timestamped { content: string; userId: User["id"] | null; @@ -42,5 +49,5 @@ export interface Token extends Created { export type TokenDigest = string; export interface ContextState { - user?: Omit & Partial; + user?: PublicUser; }