pub fn authenticate_request(
    header: Option<HeaderValue>,
    conn: &PgConnection,
) -> Result<uuid::Uuid, StatusCode> {

    let v = header.ok_or(StatusCode::UNAUTHORIZED)?;
    let jwt_str = v.to_str().map_err(|_| StatusCode::UNAUTHORIZED)?;

    let user_id =
        token_utils::decode_jwt_and_get_user_id(jwt_str).map_err(|_| StatusCode::UNAUTHORIZED)?;

    let user_option =
        find_user_by_uid(user_id, conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;

    user_option.map(|u| u.user_id).ok_or(StatusCode::NOT_FOUND)
}
/// Extract user_id from jwt token and verify in db that user by that user_id exists.
/// This should ideally have been authentication middleware of actix. Todo.
Extract user_id from jwt token and verify in db that user by that user_id exists.
This should ideally have been authentication middleware of actix. Todo.
Extract user_id from jwt token and verify in db that user by that user_id exists . This should ideally have been authentication middleware of actix . Todo .
pub fn authenticate_request(
    header: Option<HeaderValue>,
    conn: &PgConnection,
) -> Result<uuid::Uuid, StatusCode> {
    let v = header.ok_or(StatusCode::UNAUTHORIZED)?;
    let jwt_str = v.to_str().map_err(|_| StatusCode::UNAUTHORIZED)?;
    let user_id =
        token_utils::decode_jwt_and_get_user_id(jwt_str).map_err(|_| StatusCode::UNAUTHORIZED)?;
    let user_option =
        find_user_by_uid(user_id, conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
    user_option.map(|u| u.user_id).ok_or(StatusCode::NOT_FOUND)
}
pub fn authenticate_request ( header : Option < HeaderValue > , conn : & PgConnection , ) -> Result < uuid :: Uuid , StatusCode > { let v = header . ok_or ( StatusCode :: UNAUTHORIZED ) ? ; let jwt_str = v . to_str ( ) . map_err ( | _ | StatusCode :: UNAUTHORIZED ) ? ; let user_id = token_utils :: decode_jwt_and_get_user_id ( jwt_str ) . map_err ( | _ | StatusCode :: UNAUTHORIZED ) ? ; let user_option = find_user_by_uid ( user_id , conn ) . map_err ( | _ | StatusCode :: INTERNAL_SERVER_ERROR ) ? ; user_option . map ( | u | u . user_id ) . ok_or ( StatusCode :: NOT_FOUND ) }
Extract user_id from jwt token and verify in db that user by that user_id exists.
Extract user_id from jwt token and verify in db that user by that user_id exists .
header
Option<HeaderValue>
conn
&PgConnection
header
Option<HeaderValue>
conn
&PgConnection