-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
373 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: '3.9' | ||
|
||
services: | ||
server: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
use axum::Json; | ||
use axum::{extract::State, Json}; | ||
use axum_macros::debug_handler; | ||
use serde_json::{json, Value}; | ||
|
||
use crate::{errors::{Error, Result}, models::session_model::VerifyJwt, utils::session_utils::IDToken}; | ||
use crate::{core::session::Session, errors::{Error, Result}, models::{session_model::VerifyJwt, user_model::UserIdPayload}, utils::session_utils::IDToken, AppState}; | ||
|
||
#[debug_handler] | ||
pub async fn verify_jwt_handler( | ||
pub async fn verify_session( | ||
State(state): State<AppState>, | ||
payload: Json<VerifyJwt>, | ||
) -> Result<Json<Value>> { | ||
) -> Result<Json<IDToken>> { | ||
// check if the token is not empty | ||
if payload.token.is_empty() { | ||
return Err(Error::InvalidPayload { message: "Invalid payload passed".to_string() }); | ||
} | ||
|
||
// verify the token | ||
let _ = match IDToken::verify(&payload.token) { | ||
Ok(val) => return Ok(Json(json!(val))), | ||
match Session::verify(&state.mongo_client, &payload.token).await { | ||
Ok(data) => { | ||
return Ok(Json(data)); | ||
} | ||
Err(e) => return Err(e), | ||
|
||
}; | ||
} | ||
|
||
#[debug_handler] | ||
pub async fn get_all_from_uid( | ||
State(state): State<AppState>, | ||
payload: Json<UserIdPayload>, | ||
) -> Result<Json<Vec<Session>>> { | ||
// check if the token is not empty | ||
if payload.uid.is_empty() { | ||
return Err(Error::InvalidPayload { message: "Invalid payload passed".to_string() }); | ||
} | ||
|
||
// verify the token | ||
match Session::get_all_from_uid(&state.mongo_client, &payload.uid).await { | ||
Ok(data) => { | ||
return Ok(Json(data)); | ||
} | ||
Err(e) => return Err(e), | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.