..
This commit is contained in:
parent
dc20f0507a
commit
569df5ec76
|
@ -62,7 +62,7 @@ async fn get_author_id(user: &str) -> Result<i32, Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_user_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
pub async fn get_id_by_token(token: &str) -> Result<i32, Box<dyn Error>> {
|
||||||
let auth_api_base = env::var("AUTH_URL")?;
|
let auth_api_base = env::var("AUTH_URL")?;
|
||||||
let query_name = "validate_jwt_token";
|
let query_name = "validate_jwt_token";
|
||||||
let operation = "ValidateToken";
|
let operation = "ValidateToken";
|
||||||
|
@ -79,7 +79,7 @@ pub async fn get_user_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
||||||
"operationName": operation,
|
"operationName": operation,
|
||||||
"variables": variables
|
"variables": variables
|
||||||
});
|
});
|
||||||
print!("{}", gql)
|
println!("GraphQL Query: {}", gql);
|
||||||
let client = HTTPClient::new();
|
let client = HTTPClient::new();
|
||||||
let response = client
|
let response = client
|
||||||
.post(&auth_api_base)
|
.post(&auth_api_base)
|
||||||
|
@ -97,8 +97,6 @@ pub async fn get_user_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
||||||
.and_then(|claims| claims.get("sub"))
|
.and_then(|claims| claims.get("sub"))
|
||||||
.and_then(|id| id.as_str());
|
.and_then(|id| id.as_str());
|
||||||
|
|
||||||
// TODO: add get_author call to API_BASE to get author_id from user_id
|
|
||||||
|
|
||||||
match user_id {
|
match user_id {
|
||||||
Some(id) => {
|
Some(id) => {
|
||||||
println!("User ID retrieved: {}", id);
|
println!("User ID retrieved: {}", id);
|
||||||
|
|
|
@ -48,7 +48,7 @@ async fn connect_handler(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let listener_id = data::get_user_id(&token).await.map_err(|e| {
|
let listener_id = data::get_id_by_token(&token).await.map_err(|e| {
|
||||||
eprintln!("TOKEN check failed: {}", e);
|
eprintln!("TOKEN check failed: {}", e);
|
||||||
ErrorUnauthorized("Unauthorized")
|
ErrorUnauthorized("Unauthorized")
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user