fix: set cookie in header on rewrite
This commit is contained in:
@@ -10,8 +10,6 @@ import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import MaxWidth from "@/components/MaxWidth"
|
||||
import Content from "@/components/MyPages/AccountPage/Webview/Content"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import Title from "@/components/Title"
|
||||
|
||||
import styles from "./page.module.css"
|
||||
|
||||
@@ -39,6 +37,18 @@ export default async function MyPages({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
// Check if the access token is valid. If not, redirect to the refresh page.
|
||||
await serverClient({
|
||||
onError(opts) {
|
||||
const returnUrl = new URLSearchParams({
|
||||
returnurl: `${params.lang}/webview/${searchParams.uri}`,
|
||||
})
|
||||
|
||||
const refreshUrl = `/${params.lang}/webview/refresh?${returnUrl.toString()}`
|
||||
redirect(refreshUrl)
|
||||
},
|
||||
}).user.get()
|
||||
|
||||
const accountPage = await serverClient({
|
||||
onError() {
|
||||
const returnUrl = new URLSearchParams({
|
||||
@@ -57,10 +67,6 @@ export default async function MyPages({
|
||||
|
||||
return (
|
||||
<MaxWidth className={styles.blocks} tag="main">
|
||||
<header>
|
||||
<Title as="h2">{_("Welcome")}</Title>
|
||||
<Link href={link.href}>{link.title}</Link>
|
||||
</header>
|
||||
<Content lang={params.lang} content={accountPage.content} />
|
||||
</MaxWidth>
|
||||
)
|
||||
|
||||
@@ -49,12 +49,12 @@ export const points = {
|
||||
|
||||
/** @type {import('@/types/routes').LangRoute} */
|
||||
export const programOverview = {
|
||||
da: `/da/webview/ophold`,
|
||||
de: `/de/webview/aufenthalte`,
|
||||
en: `/en/webview/stays`,
|
||||
fi: `/fi/webview/oleskeluni`,
|
||||
no: `/no/webview/opphold`,
|
||||
sv: `/sv/webview/vistelser`,
|
||||
da: `/da/webview/about-scandic-friends`,
|
||||
de: `/de/webview/about-scandic-friends`,
|
||||
en: `/en/webview/about-scandic-friends`,
|
||||
fi: `/fi/webview/about-scandic-friends`,
|
||||
no: `/no/webview/om-scandic-friends`,
|
||||
sv: `/sv/webview/om-scandic-friends`,
|
||||
}
|
||||
|
||||
export const webviews = [
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { type NextMiddleware, NextResponse } from "next/server"
|
||||
|
||||
import { findLang } from "@/constants/languages"
|
||||
@@ -36,6 +37,8 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
nextUrl
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return notFound()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +72,7 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
{
|
||||
headers: {
|
||||
"Set-Cookie": `webviewToken=${decryptedData}; Secure; HttpOnly; Path=/; SameSite=Strict;`,
|
||||
Cookie: `webviewToken=${decryptedData}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -81,6 +85,7 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
{
|
||||
headers: {
|
||||
"Set-Cookie": `webviewToken=${decryptedData}; Secure; HttpOnly; Path=/; SameSite=Strict;`,
|
||||
Cookie: `webviewToken=${decryptedData}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -33,6 +33,21 @@ export function createContextInner(opts: CreateContextOptions) {
|
||||
export function createContext() {
|
||||
const h = headers()
|
||||
|
||||
// const cookie = cookies()
|
||||
// const webviewTokenCookie = cookie.get("webviewToken")
|
||||
|
||||
// if (webviewTokenCookie) {
|
||||
// // since the token exists, this is a subsequent visit
|
||||
// // we're done, allow it
|
||||
// return createContextInner({
|
||||
// session: {
|
||||
// token: { access_token: webviewTokenCookie.value },
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
|
||||
// const session = await auth()
|
||||
|
||||
return createContextInner({
|
||||
auth,
|
||||
lang: h.get("x-lang") as Lang,
|
||||
|
||||
Reference in New Issue
Block a user