ls-deno/routes/dashboard.tsx

41 lines
981 B
TypeScript
Raw Normal View History

2022-10-08 02:01:48 -05:00
import { Page } from "@/components/Page.tsx";
// import { getToken, getUser } from "@/db/mod.ts";
// import * as base64 from "$std/encoding/base64.ts";
2022-10-11 16:17:21 -05:00
import { Handlers, PageProps } from "$fresh/server.ts";
2022-10-08 02:53:13 -05:00
import { type ContextState } from "@/types.ts";
2022-10-08 02:01:48 -05:00
2022-10-08 02:53:13 -05:00
export const handler: Handlers<unknown, ContextState> = {
async GET(_request: Request, context) {
const user: Partial<ContextState["user"]> = context.state.user;
2022-10-11 16:17:21 -05:00
if (user && "passwordDigest" in user) delete user.passwordDigest;
2022-10-08 02:53:13 -05:00
return await context.render(context.state.user);
2022-10-08 02:01:48 -05:00
},
};
export default function Dashboard({ data }: PageProps) {
2022-10-08 02:53:13 -05:00
console.log(data);
2022-10-08 02:01:48 -05:00
if (data) {
return You(data);
} else {
return LoginRequired();
}
}
function You(data: unknown) {
return (
<Page>
<p>
2022-10-08 02:53:13 -05:00
You are <pre>{JSON.stringify(data)}</pre>.
2022-10-08 02:01:48 -05:00
</p>
</Page>
);
}
function LoginRequired() {
return (
<Page>
<a href="/login">You need to login first!</a>
</Page>
);
}