feat(WEB-127): add trpc to handle requests both serverside and clientside

This commit is contained in:
Simon Emanuelsson
2024-03-20 16:39:11 +01:00
parent 2087ac6c91
commit ec4da5798b
31 changed files with 422 additions and 40 deletions

View File

@@ -0,0 +1,21 @@
import { redirect } from "next/navigation"
import { auth } from "@/auth"
import type { LangParams, LayoutArgs } from "@/types/params"
export default async function ProtectedLayout({
children,
params,
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
const session = await auth()
/**
* Fallback to make sure every route nested in the
* protected route group is actually protected.
*/
if (!session) {
return redirect(`/${params.lang}/login`)
}
return <>{children}</>
}

View File

@@ -1,4 +1,4 @@
import { auth } from "@/auth"
import { serverClient } from "@/lib/trpc/server"
import Overview from "@/components/MyPages/Blocks/Overview"
import OverviewMobile from "@/components/MyPages/Blocks/Overview/Mobile"
@@ -10,12 +10,11 @@ import styles from "./page.module.css"
import type { LangParams, PageArgs } from "@/types/params"
export default async function MyPage({ params }: PageArgs<LangParams>) {
const session = await auth()
console.log({ session })
const data = await serverClient().user.get()
return (
<section className={styles.container}>
<header className={styles.header}>
<Title uppercase>Good morning {session?.user?.name ?? "[NAME]"}</Title>
<Title uppercase>Good morning {data.name}</Title>
</header>
<section className={styles.blocks}>
<Overview />