Przeglądaj źródła

fix: disable sync if keys aren't provided (#3304)

Nathan.fooo 1 rok temu
rodzic
commit
abb6eff23d

+ 9 - 1
frontend/rust-lib/flowy-core/src/integrate/server.rs

@@ -130,7 +130,15 @@ impl AppFlowyServerProvider {
         Ok::<Arc<dyn AppFlowyServer>, FlowyError>(server)
       },
       ServerProviderType::Supabase => {
-        let config = SupabaseConfiguration::from_env()?;
+        let config = match SupabaseConfiguration::from_env() {
+          Ok(config) => config,
+          Err(e) => {
+            *self.enable_sync.write() = false;
+            return Err(e);
+          },
+        };
+
+        tracing::trace!("🔑Supabase config: {:?}", config);
         let encryption = Arc::downgrade(&*self.encryption.read());
         Ok::<Arc<dyn AppFlowyServer>, FlowyError>(Arc::new(SupabaseServer::new(
           config,

+ 14 - 6
frontend/rust-lib/flowy-server-config/src/supabase_config.rs

@@ -23,12 +23,20 @@ pub struct SupabaseConfiguration {
 
 impl SupabaseConfiguration {
   pub fn from_env() -> Result<Self, FlowyError> {
-    Ok(Self {
-      url: std::env::var(SUPABASE_URL)
-        .map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_URL"))?,
-      anon_key: std::env::var(SUPABASE_ANON_KEY)
-        .map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_ANON_KEY"))?,
-    })
+    let url = std::env::var(SUPABASE_URL)
+      .map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_URL"))?;
+
+    let anon_key = std::env::var(SUPABASE_ANON_KEY)
+      .map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_ANON_KEY"))?;
+
+    if url.is_empty() || anon_key.is_empty() {
+      return Err(FlowyError::new(
+        ErrorCode::InvalidAuthConfig,
+        "Missing SUPABASE_URL or SUPABASE_ANON_KEY",
+      ));
+    }
+
+    Ok(Self { url, anon_key })
   }
 
   /// Write the configuration to the environment variables.