30 lines
688 B
Rust
30 lines
688 B
Rust
use yewdux::prelude::*;
|
|
|
|
use crate::cookies;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Store)]
|
|
pub struct LoggedIn(pub bool);
|
|
|
|
impl Default for LoggedIn {
|
|
fn default() -> Self {
|
|
let token = {
|
|
let tmp = wasm_cookies::get(cookies::names::TOKEN);
|
|
if let Some(x) = tmp {
|
|
if let Ok(y) = x {
|
|
Some(y)
|
|
} else {
|
|
wasm_cookies::delete(cookies::names::TOKEN);
|
|
None
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
};
|
|
|
|
Self(token.is_some())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Store)]
|
|
pub struct Token(pub String);
|