web: use param ?redirect=
with auth redirection and switch to a boolean check for /api/session/validate
This commit is contained in:
parent
8b06a1414d
commit
d089872432
@ -6,25 +6,19 @@ import { useEffect } from "react";
|
||||
import Header from "./header";
|
||||
|
||||
async function login_check() {
|
||||
try {
|
||||
const response = await fetch("/api/session/validate")
|
||||
if (response.ok) {
|
||||
const logged_in = await response.json()
|
||||
if (logged_in.code === 500) {
|
||||
redirect("https://auth.staging.strafes.net/")
|
||||
}
|
||||
} else {
|
||||
console.error("No response from /api/session/validate")
|
||||
const response = await fetch("/api/session/validate")
|
||||
if (response.ok) {
|
||||
const logged_in = await response.json()
|
||||
if (!logged_in) {
|
||||
redirect("https://auth.staging.strafes.net/oauth2/login?redirect=" + window.location.href)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error getting login status:", error)
|
||||
} else {
|
||||
console.error("No response from /api/session/validate")
|
||||
}
|
||||
}
|
||||
|
||||
export default function Webpage({children}: Readonly<{children?: React.ReactNode}>) {
|
||||
useEffect(() => {
|
||||
login_check()
|
||||
}, [])
|
||||
useEffect(() => { login_check() }, [])
|
||||
|
||||
return <>
|
||||
<Header/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user