Login Session/ Logout button

This commit is contained in:
2025-05-17 17:35:13 -04:00
parent d40c379216
commit 34c050384b
4 changed files with 20 additions and 7 deletions

View File

@@ -7,12 +7,18 @@ pub struct AuthContext {
}
impl AuthContext {
pub fn set_token(&mut self, token: String) {
pub fn login(&mut self, token: String) {
self.jwt.set(Some(token.clone()));
let local_storage = window().unwrap().local_storage().unwrap().unwrap();
_ = local_storage.set_item("token", token.as_str());
}
pub fn logout(&mut self) {
self.jwt.set(None);
let local_storage = window().unwrap().local_storage().unwrap().unwrap();
_ = local_storage.remove_item("token");
}
pub fn new() -> Self {
println!("new");
let local_storage = window().unwrap().local_storage().unwrap().unwrap();