web: switch to using /api/session/validate
for determining if the user is not logged in
This commit is contained in:
parent
a9afdf38cf
commit
0d2cd5fb49
@ -1,18 +1,29 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import Header from "./header";
|
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")
|
||||||
|
}
|
||||||
|
} 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}>) {
|
||||||
//check if the user is logged into the auth
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cookies = document.cookie.split("; ")
|
login_check()
|
||||||
const hasCookie = cookies.some(cookie => cookie.startsWith("session_id="))
|
|
||||||
if (!hasCookie) {
|
|
||||||
redirect("https://auth.staging.strafes.net/")
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user