2023-11-20 12:54:47 +00:00
|
|
|
use serde_repr::Deserialize_repr;
|
|
|
|
|
2023-10-02 09:22:22 +00:00
|
|
|
pub mod af_cloud_config;
|
2023-07-14 05:37:13 +00:00
|
|
|
pub mod supabase_config;
|
2023-11-20 12:54:47 +00:00
|
|
|
|
|
|
|
pub const CLOUT_TYPE_STR: &str = "APPFLOWY_CLOUD_ENV_CLOUD_TYPE";
|
|
|
|
|
2023-11-28 02:54:31 +00:00
|
|
|
#[derive(Deserialize_repr, Debug, Clone, PartialEq, Eq)]
|
2023-11-20 12:54:47 +00:00
|
|
|
#[repr(u8)]
|
|
|
|
pub enum AuthenticatorType {
|
|
|
|
Local = 0,
|
|
|
|
Supabase = 1,
|
|
|
|
AppFlowyCloud = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AuthenticatorType {
|
|
|
|
pub fn write_env(&self) {
|
|
|
|
let s = self.clone() as u8;
|
|
|
|
std::env::set_var(CLOUT_TYPE_STR, s.to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn from_str(s: &str) -> Self {
|
|
|
|
match s {
|
|
|
|
"0" => AuthenticatorType::Local,
|
|
|
|
"1" => AuthenticatorType::Supabase,
|
|
|
|
"2" => AuthenticatorType::AppFlowyCloud,
|
|
|
|
_ => AuthenticatorType::Local,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn from_env() -> Self {
|
|
|
|
let cloud_type_str = std::env::var(CLOUT_TYPE_STR).unwrap_or_default();
|
|
|
|
AuthenticatorType::from_str(&cloud_type_str)
|
|
|
|
}
|
|
|
|
}
|