mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: calling user event from web (#4535)
* refactor: user manager * refactor: user manager * refactor: session location * refactor: user manager * chore: gen ts files * feat: implement indexeddb persistence * chore: integrate user manager * chore: update * chore: run on web thread * chore: run on web thread * chore: fix test * chore: add test * chore: add test * chore: add user & sign in with password * chore: fix test * chore: update docs * chore: fix warnings * chore: gen files * chore: add user * chore: add files * chore: update config * chore: update scirpt * chore: update scirpt * fix: build * chore: update command * fix: ci * ci: fix * fix: compile * fix: compile * fix: ci * fix: compile * fix: tauri build * chore: fix test * chore: fix test
This commit is contained in:
@ -9,3 +9,4 @@ edition = "2021"
|
||||
flowy-error = { workspace = true }
|
||||
serde.workspace = true
|
||||
serde_repr.workspace = true
|
||||
|
||||
|
@ -1,6 +1,33 @@
|
||||
use serde_repr::Deserialize_repr;
|
||||
|
||||
pub mod af_cloud_config;
|
||||
macro_rules! if_native {
|
||||
($($item:item)*) => {$(
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
$item
|
||||
)*}
|
||||
}
|
||||
|
||||
macro_rules! if_wasm {
|
||||
($($item:item)*) => {$(
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
$item
|
||||
)*}
|
||||
}
|
||||
|
||||
if_native! {
|
||||
mod native;
|
||||
pub mod af_cloud_config {
|
||||
pub use crate::native::af_cloud_config::*;
|
||||
}
|
||||
}
|
||||
|
||||
if_wasm! {
|
||||
mod wasm;
|
||||
pub mod af_cloud_config {
|
||||
pub use crate::wasm::af_cloud_config::*;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod supabase_config;
|
||||
|
||||
pub const CLOUT_TYPE_STR: &str = "APPFLOWY_CLOUD_ENV_CLOUD_TYPE";
|
||||
|
@ -0,0 +1,69 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
|
||||
pub const APPFLOWY_CLOUD_BASE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_BASE_URL";
|
||||
pub const APPFLOWY_CLOUD_WS_BASE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_WS_BASE_URL";
|
||||
pub const APPFLOWY_CLOUD_GOTRUE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_GOTRUE_URL";
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct AFCloudConfiguration {
|
||||
pub base_url: String,
|
||||
pub ws_base_url: String,
|
||||
pub gotrue_url: String,
|
||||
}
|
||||
|
||||
impl Display for AFCloudConfiguration {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"base_url: {}, ws_base_url: {}, gotrue_url: {}",
|
||||
self.base_url, self.ws_base_url, self.gotrue_url,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl AFCloudConfiguration {
|
||||
pub fn from_env() -> Result<Self, FlowyError> {
|
||||
let base_url = std::env::var(APPFLOWY_CLOUD_BASE_URL).map_err(|_| {
|
||||
FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
"Missing APPFLOWY_CLOUD_BASE_URL",
|
||||
)
|
||||
})?;
|
||||
|
||||
let ws_base_url = std::env::var(APPFLOWY_CLOUD_WS_BASE_URL).map_err(|_| {
|
||||
FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
"Missing APPFLOWY_CLOUD_WS_BASE_URL",
|
||||
)
|
||||
})?;
|
||||
|
||||
let gotrue_url = std::env::var(APPFLOWY_CLOUD_GOTRUE_URL)
|
||||
.map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing AF_CLOUD_GOTRUE_URL"))?;
|
||||
|
||||
if base_url.is_empty() || ws_base_url.is_empty() || gotrue_url.is_empty() {
|
||||
return Err(FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
format!(
|
||||
"Invalid APPFLOWY_CLOUD_BASE_URL: {}, APPFLOWY_CLOUD_WS_BASE_URL: {}, APPFLOWY_CLOUD_GOTRUE_URL: {}",
|
||||
base_url, ws_base_url, gotrue_url,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
base_url,
|
||||
ws_base_url,
|
||||
gotrue_url,
|
||||
})
|
||||
}
|
||||
|
||||
/// Write the configuration to the environment variables.
|
||||
pub fn write_env(&self) {
|
||||
std::env::set_var(APPFLOWY_CLOUD_BASE_URL, &self.base_url);
|
||||
std::env::set_var(APPFLOWY_CLOUD_WS_BASE_URL, &self.ws_base_url);
|
||||
std::env::set_var(APPFLOWY_CLOUD_GOTRUE_URL, &self.gotrue_url);
|
||||
}
|
||||
}
|
1
frontend/rust-lib/flowy-server-pub/src/native/mod.rs
Normal file
1
frontend/rust-lib/flowy-server-pub/src/native/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod af_cloud_config;
|
@ -0,0 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct AFCloudConfiguration {
|
||||
pub base_url: String,
|
||||
pub ws_base_url: String,
|
||||
pub gotrue_url: String,
|
||||
}
|
||||
|
||||
impl Display for AFCloudConfiguration {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"base_url: {}, ws_base_url: {}, gotrue_url: {}",
|
||||
self.base_url, self.ws_base_url, self.gotrue_url,
|
||||
))
|
||||
}
|
||||
}
|
1
frontend/rust-lib/flowy-server-pub/src/wasm/mod.rs
Normal file
1
frontend/rust-lib/flowy-server-pub/src/wasm/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod af_cloud_config;
|
Reference in New Issue
Block a user