query-type-fix
This commit is contained in:
parent
510ac17375
commit
5526ebe7c9
14
src/data.rs
14
src/data.rs
|
@ -6,16 +6,16 @@ use std::env;
|
|||
|
||||
pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
||||
let auth_api_base = env::var("AUTH_URL")?;
|
||||
let queryname = match auth_api_base.contains("discours.io") {
|
||||
true => "getSession", // v2
|
||||
_ => "session" // authorizer
|
||||
let (query_name, query_type) = match auth_api_base.contains("discours.io") {
|
||||
true => ("getSession", "mutation"), // v2
|
||||
_ => ("session", "query") // authorizer
|
||||
};
|
||||
|
||||
let body = format!(r#"{{
|
||||
"query": "mutation GetSessionMutation {{ {} {{ user {{ id }} }} }}",
|
||||
"operationName": "GetSessionMutation",
|
||||
"query": "{} GetSession {{ {} {{ user {{ id }} }} }}",
|
||||
"operationName": "GetSession",
|
||||
"variables": {{}}
|
||||
}}"#, queryname);
|
||||
}}"#, query_type, query_name);
|
||||
|
||||
let client = HTTPClient::new();
|
||||
let response = client
|
||||
|
@ -25,7 +25,7 @@ pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
|
|||
.send()
|
||||
.await?;
|
||||
let response_body: Value = response.json().await?;
|
||||
let id = response_body["data"][queryname]["user"]["id"]
|
||||
let id = response_body["data"][query_name]["user"]["id"]
|
||||
.as_i64()
|
||||
.ok_or("Failed to get user id by token")? as i32;
|
||||
Ok(id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user