fix: auth routing
This commit is contained in:
@@ -91,6 +91,8 @@ export function strip(pathname: string) {
|
|||||||
export function route(locale: Locale, pathname: string) {
|
export function route(locale: Locale, pathname: string) {
|
||||||
const next = strip(pathname)
|
const next = strip(pathname)
|
||||||
if (next.startsWith("/docs")) return next
|
if (next.startsWith("/docs")) return next
|
||||||
|
if (next.startsWith("/auth")) return next
|
||||||
|
if (next.startsWith("/workspace")) return next
|
||||||
if (locale === "en") return next
|
if (locale === "en") return next
|
||||||
if (next === "/") return `/${locale}`
|
if (next === "/") return `/${locale}`
|
||||||
return `/${locale}${next}`
|
return `/${locale}${next}`
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { redirect } from "@solidjs/router"
|
|||||||
import type { APIEvent } from "@solidjs/start/server"
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
import { AuthClient } from "~/context/auth"
|
import { AuthClient } from "~/context/auth"
|
||||||
import { useAuthSession } from "~/context/auth"
|
import { useAuthSession } from "~/context/auth"
|
||||||
import { fromPathname, localeFromRequest, route } from "~/lib/language"
|
import { localeFromRequest, route } from "~/lib/language"
|
||||||
|
|
||||||
export async function GET(input: APIEvent) {
|
export async function GET(input: APIEvent) {
|
||||||
const url = new URL(input.request.url)
|
const url = new URL(input.request.url)
|
||||||
@@ -31,7 +31,6 @@ export async function GET(input: APIEvent) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
const next = url.pathname === "/auth/callback" ? "/auth" : url.pathname.replace("/auth/callback", "")
|
const next = url.pathname === "/auth/callback" ? "/auth" : url.pathname.replace("/auth/callback", "")
|
||||||
if (fromPathname(next)) return redirect(next)
|
|
||||||
return redirect(route(locale, next))
|
return redirect(route(locale, next))
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return new Response(
|
return new Response(
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ export async function GET(input: APIEvent) {
|
|||||||
const workspaceID = await getLastSeenWorkspaceID()
|
const workspaceID = await getLastSeenWorkspaceID()
|
||||||
return redirect(route(locale, `/workspace/${workspaceID}`))
|
return redirect(route(locale, `/workspace/${workspaceID}`))
|
||||||
} catch {
|
} catch {
|
||||||
const cont = route(locale, "/auth")
|
return redirect("/auth/authorize")
|
||||||
if (cont === "/auth") return redirect("/auth/authorize")
|
|
||||||
return redirect(`/auth/authorize?continue=${encodeURIComponent(cont)}`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user