ntfy/web/src/app/Session.js

32 lines
606 B
JavaScript
Raw Normal View History

2022-12-02 20:37:48 +00:00
class Session {
store(username, token) {
localStorage.setItem("user", username);
localStorage.setItem("token", token);
}
reset() {
localStorage.removeItem("user");
localStorage.removeItem("token");
}
2022-12-26 03:29:55 +00:00
resetAndRedirect(url) {
this.reset();
window.location.href = url;
}
2022-12-08 01:44:20 +00:00
exists() {
return this.username() && this.token();
}
2022-12-02 20:37:48 +00:00
username() {
return localStorage.getItem("user");
}
token() {
return localStorage.getItem("token");
}
}
const session = new Session();
export default session;