switch to mongodb, add drag&drop
This commit is contained in:
41
frontend/src/services/mod.rs
Normal file
41
frontend/src/services/mod.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
pub mod auth;
|
||||
pub mod requests;
|
||||
|
||||
use dotenv_codegen::dotenv;
|
||||
|
||||
pub use requests::{request_delete, request_get, request_post, request_put};
|
||||
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
const API_ROOT: &str = dotenv!("API_ROOT");
|
||||
const TOKEN_KEY: &str = "jheuel-token";
|
||||
|
||||
lazy_static! {
|
||||
/// Jwt token read from local storage.
|
||||
pub static ref TOKEN: RwLock<Option<String>> = {
|
||||
if let Ok(token) = LocalStorage::get(TOKEN_KEY) {
|
||||
RwLock::new(Some(token))
|
||||
} else {
|
||||
RwLock::new(None)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Set jwt token to local storage.
|
||||
pub fn set_token(token: Option<String>) {
|
||||
if let Some(t) = token.clone() {
|
||||
LocalStorage::set(TOKEN_KEY, t).expect("failed to set");
|
||||
} else {
|
||||
LocalStorage::delete(TOKEN_KEY);
|
||||
}
|
||||
let mut token_lock = TOKEN.write();
|
||||
*token_lock = token;
|
||||
}
|
||||
|
||||
/// Get jwt token from lazy static.
|
||||
pub fn get_token() -> Option<String> {
|
||||
let token_lock = TOKEN.read();
|
||||
token_lock.clone()
|
||||
}
|
||||
Reference in New Issue
Block a user