Merged in feat/user-data (pull request #71)
Feat/user data Approved-by: Christel Westerberg
This commit is contained in:
21
app/[lang]/(live)/(protected)/layout.tsx
Normal file
21
app/[lang]/(live)/(protected)/layout.tsx
Normal 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}</>
|
||||
}
|
||||
@@ -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 />
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { SessionProvider } from "next-auth/react"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
|
||||
import AdobeScript from "@/components/Current/AdobeScript"
|
||||
import Script from "next/script"
|
||||
import TrpcProvider from "@/lib/trpc/Provider"
|
||||
import VwoScript from "@/components/Current/VwoScript"
|
||||
|
||||
import type { Metadata } from "next"
|
||||
@@ -12,10 +17,11 @@ export const metadata: Metadata = {
|
||||
title: "Scandic Hotels New Web",
|
||||
}
|
||||
|
||||
export default function RootLayout({
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
params,
|
||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||
const session = await auth()
|
||||
return (
|
||||
<html lang={params.lang}>
|
||||
<head>
|
||||
@@ -38,7 +44,9 @@ export default function RootLayout({
|
||||
<VwoScript />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<SessionProvider session={session}>
|
||||
<TrpcProvider>{children}</TrpcProvider>
|
||||
</SessionProvider>
|
||||
<Script id="page-tracking">{`
|
||||
typeof _satellite !== "undefined" && _satellite.pageBottom();
|
||||
`}</Script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { request } from "@/lib/request"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||
import { GetCurrentBlockPageTrackingData } from "@/lib/graphql/Query/CurrentBlockPageTrackingData.graphql"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { previewRequest } from "@/lib/previewRequest"
|
||||
import { previewRequest } from "@/lib/graphql/previewRequest"
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||
|
||||
import type { PageArgs, LangParams, PreviewParams } from "@/types/params"
|
||||
|
||||
15
app/api/trpc/[trpc]/route.ts
Normal file
15
app/api/trpc/[trpc]/route.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
||||
|
||||
import { appRouter } from "@/server"
|
||||
import { createContext } from "@/server/context"
|
||||
|
||||
async function handler(req: Request) {
|
||||
return fetchRequestHandler({
|
||||
createContext,
|
||||
endpoint: "/api/trpc",
|
||||
req,
|
||||
router: appRouter,
|
||||
})
|
||||
}
|
||||
|
||||
export { handler as GET, handler as POST }
|
||||
Reference in New Issue
Block a user