logout buton
This commit is contained in:
48
src/App.jsx
48
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
|
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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user