did some work on the user session and components
This commit is contained in:
parent
33dc08bb82
commit
350c767a13
11 changed files with 172 additions and 60 deletions
|
@ -1,10 +1,36 @@
|
|||
import { Meta } from "@solidjs/meta";
|
||||
import { query, createAsync, action } from "@solidjs/router";
|
||||
import { query, createAsync } from "@solidjs/router";
|
||||
import { createEffect, on, ParentProps } from "solid-js";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { auth } from "~/auth";
|
||||
import { Shell } from "~/features/shell";
|
||||
import { useTheme } from "~/features/theme";
|
||||
import { User } from "~/features/user";
|
||||
|
||||
const load = query(async (): Promise<User | undefined> => {
|
||||
"use server";
|
||||
|
||||
const session = await auth.api.getSession({
|
||||
headers: getRequestEvent()!.request.headers,
|
||||
});
|
||||
|
||||
if (session === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { name, email, image = null } = session.user;
|
||||
|
||||
return { name, email, image };
|
||||
}, "session");
|
||||
|
||||
export const route = {
|
||||
async preload() {
|
||||
return load();
|
||||
},
|
||||
};
|
||||
|
||||
export default function ShellPage(props: ParentProps) {
|
||||
const user = createAsync(() => load());
|
||||
const themeContext = useTheme();
|
||||
|
||||
createEffect(
|
||||
|
@ -17,7 +43,7 @@ export default function ShellPage(props: ParentProps) {
|
|||
);
|
||||
|
||||
return (
|
||||
<Shell>
|
||||
<Shell user={user()}>
|
||||
<Meta name="color-scheme" content={themeContext.theme.colorScheme} />
|
||||
|
||||
{props.children}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue