41 lines
976 B
TypeScript
41 lines
976 B
TypeScript
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, type PublicUser } from "@/types.ts";
|
|
|
|
export const handler: Handlers<unknown, ContextState> = {
|
|
async GET(_request: Request, context) {
|
|
const user: PublicUser | undefined = context.state.user;
|
|
if (user != undefined) delete user.passwordDigest;
|
|
return await context.render(context.state.user);
|
|
},
|
|
};
|
|
|
|
export default function Dashboard({ data }: PageProps) {
|
|
console.log(data);
|
|
if (data) {
|
|
return You(data);
|
|
} else {
|
|
return LoginRequired();
|
|
}
|
|
}
|
|
|
|
function You(data: unknown) {
|
|
return (
|
|
<Page>
|
|
<p>
|
|
You are <pre>{JSON.stringify(data)}</pre>.
|
|
</p>
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
function LoginRequired() {
|
|
return (
|
|
<Page>
|
|
<a href="/login">You need to login first!</a>
|
|
</Page>
|
|
);
|
|
}
|