fix: redirect users to /refresh on unauth and mod webview links

This commit is contained in:
Christel Westerberg
2024-05-16 16:57:22 +02:00
parent 777fd1e5b6
commit 9e4f41ee46
29 changed files with 358 additions and 105 deletions

View File

@@ -1,14 +1,14 @@
import { notFound, redirect } from "next/navigation"
import { notFound } from "next/navigation"
import { serverClient } from "@/lib/trpc/server"
import { Blocks } from "@/components/Loyalty/Blocks"
import { Blocks } from "@/components/Loyalty/Blocks/WebView"
import Sidebar from "@/components/Loyalty/Sidebar"
import MaxWidth from "@/components/MaxWidth"
import styles from "./page.module.css"
import type { LangParams, PageArgs, UriParams } from "@/types/params"
import { LangParams, PageArgs, UriParams } from "@/types/params"
export default async function AboutScandicFriends({
params,
@@ -18,26 +18,16 @@ export default async function AboutScandicFriends({
return notFound()
}
const loyaltyPage = await serverClient({
onError() {
const returnUrl = new URLSearchParams({
returnurl: `${params.lang}/webview/${searchParams.uri}`,
})
const refreshUrl = `/${params.lang}/webview/refresh?${returnUrl.toString()}`
redirect(refreshUrl)
},
}).contentstack.loyaltyPage.get({
const loyaltyPage = await serverClient().contentstack.loyaltyPage.get({
href: searchParams.uri,
locale: params.lang,
})
return (
<section className={styles.content}>
{loyaltyPage.sidebar ? <Sidebar blocks={loyaltyPage.sidebar} /> : null}
<MaxWidth className={styles.blocks} tag="main">
<Blocks blocks={loyaltyPage.blocks} />
<Blocks blocks={loyaltyPage.blocks} lang={params.lang} />
</MaxWidth>
</section>
)

View File

@@ -1,10 +1,8 @@
import "@/app/globals.css"
import "@scandic-hotels/design-system/style.css"
import { notFound, redirect } from "next/navigation"
import { notFound } from "next/navigation"
import { Lang } from "@/constants/languages"
import { overview } from "@/constants/routes/webviews"
import { _ } from "@/lib/translation"
import { serverClient } from "@/lib/trpc/server"
@@ -13,21 +11,7 @@ import Content from "@/components/MyPages/AccountPage/Webview/Content"
import styles from "./page.module.css"
import type { LangParams, PageArgs, UriParams } from "@/types/params"
function getLink(lang: Lang, uri: string) {
if (uri === overview[lang]) {
return {
title: _("Go to points"),
href: `/${lang}/webview/my-pages/points`,
}
} else {
return {
title: _("Go to membership overview"),
href: `/${lang}/webview/my-pages/overview`,
}
}
}
import { LangParams, PageArgs, UriParams } from "@/types/params"
export default async function MyPages({
params,
@@ -37,34 +21,11 @@ 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({
returnurl: `${params.lang}/webview/${searchParams.uri}`,
})
const refreshUrl = `/${params.lang}/webview/refresh?${returnUrl.toString()}`
redirect(refreshUrl)
},
}).contentstack.accountPage.get({
const accountPage = await serverClient().contentstack.accountPage.get({
url: searchParams.uri,
lang: params.lang,
})
const link = getLink(params.lang, searchParams.uri)
return (
<MaxWidth className={styles.blocks} tag="main">
<Content lang={params.lang} content={accountPage.content} />

View File

@@ -0,0 +1,3 @@
export default function Refresh() {
return <div>Hey you&apos;ve been refreshed</div>
}