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

@@ -0,0 +1,16 @@
#import "../Fragments/Image.graphql"
query GetMyPagesLogo($locale: String!) {
all_header(limit: 1, locale: $locale) {
items {
logoConnection {
edges {
node {
...Image
}
}
totalCount
}
}
}
}

View File

@@ -1,4 +1,5 @@
import { TRPCError } from "@trpc/server"
import { headers } from "next/headers"
import { redirect } from "next/navigation"
import { Lang } from "@/constants/languages"
@@ -22,6 +23,16 @@ export function serverClient() {
if (error instanceof TRPCError) {
if (error.code === "UNAUTHORIZED") {
const lang = ctx?.lang || Lang.en
if (ctx?.webToken) {
const returnUrl = ctx.url
const redirectUrl = `/${lang}/webview/refresh?returnurl=${encodeURIComponent(returnUrl)}`
console.error(
"Unautorized in webview, redirecting to: ",
redirectUrl
)
redirect(redirectUrl)
}
const pathname = ctx?.pathname || "/"
redirect(
`/${lang}/login?redirectTo=${encodeURIComponent(`/${lang}/${pathname}`)}`