Add auth
This commit is contained in:
parent
e1ba3d44c7
commit
dda356ea00
8 changed files with 60 additions and 0 deletions
14
backend/sync_server/src/server/auth.rs
Normal file
14
backend/sync_server/src/server/auth.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use crate::{
|
||||
app_state::AppState,
|
||||
config::user_config::User,
|
||||
errors::{unauthorized_error, SyncServerError},
|
||||
};
|
||||
|
||||
pub fn auth(app_state: &AppState, token: &str) -> Result<User, SyncServerError> {
|
||||
app_state
|
||||
.config
|
||||
.users
|
||||
.get_user(token)
|
||||
.cloned()
|
||||
.ok_or_else(|| unauthorized_error(anyhow::anyhow!("Invalid token")))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue