logout buton
This commit is contained in:
40
src/App.jsx
40
src/App.jsx
@@ -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
|
||||
|
||||
// Show main app if logged in, otherwise show login
|
||||
return loggedIn ? (
|
||||
return (
|
||||
<>
|
||||
<button onClick={logoutUser}>disconnect</button>
|
||||
|
||||
{loggedIn ? (
|
||||
<MainApp resClientId={clientId} />
|
||||
) : (
|
||||
<Login onLogin={checkAuth} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//export default App
|
||||
|
||||
@@ -291,6 +291,8 @@ export function HotelProvider({ accessToken, children, resClientId}) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// --- ADMIN PORTAL ----
|
||||
|
||||
function registerUser(username,password,hotel_ids, displayname) {
|
||||
|
||||
Reference in New Issue
Block a user