logout buton

This commit is contained in:
2026-01-15 01:03:25 +01:00
parent cd459a1aa0
commit 7039e6b149
2 changed files with 44 additions and 6 deletions

View File

@@ -51,15 +51,51 @@ async function checkAuth() {
} }
} }
async function logoutUser() {
try {
const res = await fetch(`${API_BASE}/auth/logout_single_device`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "react-app",
},
credentials: "include", // send cookies automatically
body: JSON.stringify({
device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", // or persistent device ID
}),
});
const data = await res.json();
localStorage.setItem("access_tokens", JSON.stringify(data.tokens));
setClientId(data.user_id);
setLoggedIn(false);
} finally {
checkAuth();
}
}
if (loading) return <p>Loading...</p>; // can show a spinner if (loading) return <p>Loading...</p>; // can show a spinner
// Show main app if logged in, otherwise show login return (
return loggedIn ? ( <>
<MainApp resClientId ={clientId} /> <button onClick={logoutUser}>disconnect</button>
) : (
<Login onLogin={checkAuth} /> {loggedIn ? (
); <MainApp resClientId={clientId} />
) : (
<Login onLogin={checkAuth} />
)}
</>
);
} }
//export default App //export default App

View File

@@ -291,6 +291,8 @@ export function HotelProvider({ accessToken, children, resClientId}) {
} }
// --- ADMIN PORTAL ---- // --- ADMIN PORTAL ----
function registerUser(username,password,hotel_ids, displayname) { function registerUser(username,password,hotel_ids, displayname) {