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

This commit is contained in:
Nathan.fooo 2023-09-01 11:32:45 +08:00 committed by GitHub
parent 3b4f8e53a2
commit abb6eff23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -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,

View File

@ -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.