logout all device impl
This commit is contained in:
35
src/App.jsx
35
src/App.jsx
@@ -22,6 +22,10 @@ export default function App() {
|
||||
const [updateCurrentPassword, setUpdateCurrentPassword] = useState("");
|
||||
const [updateNewPassword, setUpdateNewPassword] = useState("");
|
||||
|
||||
const accessToken = localStorage.getItem("access_tokens");
|
||||
const tokens = JSON.parse(accessToken)
|
||||
const accessTokenSingle = tokens[0];
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
checkAuth();
|
||||
@@ -82,6 +86,36 @@ async function logoutUser() {
|
||||
}
|
||||
}
|
||||
|
||||
async function logoutAllSessions() {
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/auth/logout_all_devices`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "react-app",
|
||||
Authorization: `Bearer ${accessTokenSingle}`
|
||||
},
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function updatePassword(e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -113,6 +147,7 @@ function updatePassword(e) {
|
||||
return (
|
||||
<>
|
||||
<button onClick={logoutUser}>disconnect</button>
|
||||
<button onClick={logoutAllSessions}>disconnect all session</button>
|
||||
|
||||
<form onSubmit={updatePassword}>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user