diff --git a/Cargo.lock b/Cargo.lock index 91735933..57f1a99c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1598,6 +1598,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "tracing", ] [[package]] diff --git a/libs/gotrue-entity/src/lib.rs b/libs/gotrue-entity/src/lib.rs index e2e1fed2..4f552b04 100644 --- a/libs/gotrue-entity/src/lib.rs +++ b/libs/gotrue-entity/src/lib.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::fmt::Formatter; use std::{collections::BTreeMap, fmt::Display}; #[derive(Debug, Serialize, Deserialize)] @@ -99,6 +100,15 @@ pub struct GoTrueError { pub error_id: Option, } +impl Display for GoTrueError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!( + "gotrue error: {} code: {}, error_id: {:?}", + self.msg, self.code, self.error_id + )) + } +} + impl From for GoTrueError { fn from(value: anyhow::Error) -> Self { GoTrueError { diff --git a/libs/gotrue/Cargo.toml b/libs/gotrue/Cargo.toml index b50854c0..80e95c3f 100644 --- a/libs/gotrue/Cargo.toml +++ b/libs/gotrue/Cargo.toml @@ -13,4 +13,5 @@ anyhow = "1.0.75" reqwest = { version = "0.11.20", default-features = false, features = ["json", "rustls-tls", "cookies"] } tokio = { version = "1.0.1", features = ["sync", "macros"] } infra = { path = "../infra" } -gotrue-entity = { path = "../gotrue-entity" } \ No newline at end of file +gotrue-entity = { path = "../gotrue-entity" } +tracing = "0.1" \ No newline at end of file diff --git a/libs/gotrue/src/api.rs b/libs/gotrue/src/api.rs index 435e3de9..a63d9f7f 100644 --- a/libs/gotrue/src/api.rs +++ b/libs/gotrue/src/api.rs @@ -25,6 +25,7 @@ impl Client { format!("{}/authorize?provider={}", self.base_url, provider.as_str()) } + #[tracing::instrument(skip_all, err)] pub async fn health(&self) -> Result<(), GoTrueError> { let url: String = format!("{}/health", self.base_url); let resp = self @@ -36,6 +37,7 @@ impl Client { Ok(check_response(resp).await?) } + #[tracing::instrument(skip_all, err)] pub async fn settings(&self) -> Result { let url: String = format!("{}/settings", self.base_url); let resp = self.client.get(&url).send().await?; @@ -45,6 +47,7 @@ impl Client { Ok(settings) } + #[tracing::instrument(skip_all, err)] pub async fn sign_up(&self, email: &str, password: &str) -> Result { let payload = serde_json::json!({ "email": email, @@ -55,6 +58,7 @@ impl Client { to_gotrue_result(resp).await } + #[tracing::instrument(skip_all, err)] pub async fn token(&self, grant: &Grant) -> Result { let url = format!("{}/token?grant_type={}", self.base_url, grant.type_as_str()); let payload = grant.json_value(); @@ -69,6 +73,7 @@ impl Client { } } + #[tracing::instrument(skip_all, err)] pub async fn logout(&self, access_token: &str) -> Result<(), GoTrueError> { let resp = self .client @@ -79,10 +84,12 @@ impl Client { Ok(check_response(resp).await?) } + #[tracing::instrument(skip_all, err)] pub async fn user_info(&self, access_token: &str) -> Result { + let url = format!("{}/user", self.base_url); let resp = self .client - .get(format!("{}/user", self.base_url)) + .get(&url) .header("Authorization", format!("Bearer {}", access_token)) .send() .await?; diff --git a/nginx/nginx.conf b/nginx/nginx.conf index bea6f276..4f03f249 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -14,18 +14,9 @@ http { listen 443 ssl; # GoTrue - location /verify { - proxy_pass http://gotrue:9999; - } - location /authorize { - proxy_pass http://gotrue:9999; - } - location /callback { - proxy_pass http://gotrue:9999; - } - location /settings{ - proxy_pass http://gotrue:9999; - } + location ~ ^/(verify|authorize|callback|settings|user) { + proxy_pass http://gotrue:9999; + } # AppFlowy-Cloud location / { diff --git a/tests/user/sign_up.rs b/tests/user/sign_up.rs index 580bf0b3..dd932a15 100644 --- a/tests/user/sign_up.rs +++ b/tests/user/sign_up.rs @@ -2,7 +2,7 @@ use gotrue_entity::OAuthProvider; use shared_entity::error_code::ErrorCode; use crate::{ - localhost_client, + localhost_client, test_appflowy_cloud_client, user::utils::{generate_unique_email, generate_unique_registered_user_client}, }; @@ -70,10 +70,13 @@ async fn sign_up_with_google_oauth() { .unwrap(); assert!(!url.is_empty()); - // let c = test_appflowy_cloud_client(); - // let url = c - // .generate_oauth_url_with_provider(&OAuthProvider::Google) - // .await - // .unwrap(); - // assert!(!url.is_empty()); + let c = test_appflowy_cloud_client(); + let url = c + .generate_oauth_url_with_provider(&OAuthProvider::Google) + .await + .unwrap(); + assert!(!url.is_empty()); + + // let a = r#"appflowy-flutter://#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTY0MzExODAsImlhdCI6MTY5NjQyNzU4MCwic3ViIjoiZWQ4Y2RhMzUtM2Q5MC00YTdjLWI3NTEtMzA2OWQ5Nzk4ZTZiIiwiZW1haWwiOiJuYXRoYW5AYXBwZmxvd3kuaW8iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6Imdvb2dsZSIsInByb3ZpZGVycyI6WyJnb29nbGUiXX0sInVzZXJfbWV0YWRhdGEiOnsiYXZhdGFyX3VybCI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FDZzhvY0lHb2tMeFE2U2dWY2F3UERwcmYxY05abVV3MU5yXzF0djR5bXlTc2VvaT1zOTYtYyIsImN1c3RvbV9jbGFpbXMiOnsiaGQiOiJhcHBmbG93eS5pbyJ9LCJlbWFpbCI6Im5hdGhhbkBhcHBmbG93eS5pbyIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJmdWxsX25hbWUiOiJOYXRoYW4gRm9vIiwiaXNzIjoiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tIiwibmFtZSI6Ik5hdGhhbiBGb28iLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUNnOG9jSUdva0x4UTZTZ1ZjYXdQRHByZjFjTlptVXcxTnJfMXR2NHlteVNzZW9pPXM5Ni1jIiwicHJvdmlkZXJfaWQiOiIxMDk0ODEzOTczMjQ4MjM2Mzk0MzUiLCJzdWIiOiIxMDk0ODEzOTczMjQ4MjM2Mzk0MzUifSwicm9sZSI6IiIsImFhbCI6ImFhbDEiLCJhbXIiOlt7Im1ldGhvZCI6Im9hdXRoIiwidGltZXN0YW1wIjoxNjk2NDI3NTgwfV0sInNlc3Npb25faWQiOiIyNzkwOGExNS02MDIxLTQ4MjctOTNhOS0wZGU3Y2EwYjg3MjgifQ.UNCSfcIVqFRRRtTkhGipEXBOleHQt35lhbMaIYLZuv4&expires_at=1696431180&expires_in=3600&provider_token=ya29.a0AfB_byDtFDX9UfiXw3IKzGTrZeebaQCxheWpqVg3tZi5jCWdKmZRBFsh7p7k0svqxaaX8rqN0lQsFeBbdGtd7KOSYtjsfcOkpHMH0d1fMSxrlyl_KkuvlkJe9q_X4SvpsJmx0VsVZ1CMypszLd4nzZitB0KotQPMzFMaCgYKAcASARESFQGOcNnC8cf9LzY-ZeirJHIwfL9r8w0170&refresh_token=tXCWxsp3cQF8U2307mGuMQ&token_type=bearer"#; + // c.sign_in_with_url(a).await.unwrap(); }