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,4 +1,4 @@
import { headers } from "next/headers"
import { cookies, headers } from "next/headers"
import { Lang } from "@/constants/languages"
@@ -10,6 +10,7 @@ type CreateContextOptions = {
pathname: string
uid?: string | null
url: string
webToken: string | undefined
}
/** Use this helper for:
@@ -23,6 +24,7 @@ export function createContextInner(opts: CreateContextOptions) {
pathname: opts.pathname,
uid: opts.uid,
url: opts.url,
webToken: opts.webToken,
}
}
@@ -33,20 +35,8 @@ 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()
const cookie = cookies()
const webviewTokenCookie = cookie.get("webviewToken")
return createContextInner({
auth,
@@ -54,6 +44,7 @@ export function createContext() {
pathname: h.get("x-pathname")!,
uid: h.get("x-uid"),
url: h.get("x-url")!,
webToken: webviewTokenCookie?.value,
})
}