web: use param ?redirect= with auth redirection and switch to a boolean check for /api/session/validate

This commit is contained in:
rhpidfyre 2025-03-27 12:17:04 -04:00
parent 8b06a1414d
commit d089872432

@ -6,25 +6,19 @@ import { useEffect } from "react";
import Header from "./header"; import Header from "./header";
async function login_check() { async function login_check() {
try {
const response = await fetch("/api/session/validate") const response = await fetch("/api/session/validate")
if (response.ok) { if (response.ok) {
const logged_in = await response.json() const logged_in = await response.json()
if (logged_in.code === 500) { if (!logged_in) {
redirect("https://auth.staging.strafes.net/") redirect("https://auth.staging.strafes.net/oauth2/login?redirect=" + window.location.href)
} }
} else { } else {
console.error("No response from /api/session/validate") console.error("No response from /api/session/validate")
} }
} catch (error) {
console.error("Error getting login status:", error)
}
} }
export default function Webpage({children}: Readonly<{children?: React.ReactNode}>) { export default function Webpage({children}: Readonly<{children?: React.ReactNode}>) {
useEffect(() => { useEffect(() => { login_check() }, [])
login_check()
}, [])
return <> return <>
<Header/> <Header/>