diff --git a/src/data.rs b/src/data.rs index 59f8770..81a924c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -6,16 +6,16 @@ use std::env; pub async fn get_auth_id(token: &str) -> Result> { 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> { .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)