fix: refactor session handling
This commit is contained in:
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { webviews } from "@/constants/routes/webviews"
|
||||
import { env } from "@/env/server"
|
||||
import { appRouter } from "@/server"
|
||||
import { createContext } from "@/server/context"
|
||||
@@ -24,8 +25,12 @@ 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 langIndex = ctx!.url.indexOf(`/${lang}`)
|
||||
const pathname = ctx?.url.substring(langIndex)
|
||||
|
||||
if (pathname && webviews.includes(pathname)) {
|
||||
const returnUrl = ctx!.url
|
||||
|
||||
const redirectUrl = `/${lang}/webview/refresh?returnurl=${encodeURIComponent(returnUrl)}`
|
||||
console.error(
|
||||
@@ -36,8 +41,6 @@ export function serverClient() {
|
||||
redirect(redirectUrl)
|
||||
}
|
||||
|
||||
const pathname = ctx?.pathname || "/"
|
||||
|
||||
redirect(
|
||||
`/${lang}/login?redirectTo=${encodeURIComponent(`/${lang}/${pathname}`)}`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user