Add: Handle logout
This commit is contained in:
@@ -81,6 +81,7 @@ func NewAPI(config Config) (*API, error) {
|
|||||||
// user
|
// user
|
||||||
apiMux.HandleFunc("/login", api.HandleLogin)
|
apiMux.HandleFunc("/login", api.HandleLogin)
|
||||||
apiMux.HandleFunc("/register", api.HandleRegister)
|
apiMux.HandleFunc("/register", api.HandleRegister)
|
||||||
|
apiMux.HandleFunc("/logout", api.LoginAsAnonymous)
|
||||||
// below needs token
|
// below needs token
|
||||||
apiMux.HandleFunc("/walk", api.HandleWalk)
|
apiMux.HandleFunc("/walk", api.HandleWalk)
|
||||||
apiMux.HandleFunc("/reset", api.HandleReset)
|
apiMux.HandleFunc("/reset", api.HandleReset)
|
||||||
|
|||||||
@@ -39,7 +39,21 @@ function Manage(props) {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{props.user.role !== 0 && (
|
{props.user.role !== 0 && (
|
||||||
<button onClick={() => props.setUser({})}>Logout</button>
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
fetch("/api/v1/logout")
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((data) => {
|
||||||
|
if (data.error) {
|
||||||
|
alert(data.error);
|
||||||
|
} else {
|
||||||
|
props.setUser(data.user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Logout
|
||||||
|
</button>
|
||||||
)}
|
)}
|
||||||
<hr />
|
<hr />
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ function Register(props) {
|
|||||||
if (data.error) {
|
if (data.error) {
|
||||||
alert(data.error);
|
alert(data.error);
|
||||||
} else {
|
} else {
|
||||||
props.setUser(data.user);
|
navigate("/manage/login");
|
||||||
navigate("/login");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user