AppFlowy-IO / AppFlowy-Cloud

AppFlowy is an open-source alternative to Notion. You are in charge of your data and customizations. Built with Flutter and Rust.
GNU Affero General Public License v3.0
973 stars 202 forks source link

[Bug] Tries to create existing amin account #544

Open henri9813 opened 4 months ago

henri9813 commented 4 months ago

Describe the bug At each appflowy cloud start

appflowy_cloud-1  | {"timestamp":"2024-05-09T11:39:38.105850Z","level":"ERROR","fields":{"error":"code: 400, msg:User already registered, error_id: None"},"target":"gotrue::api","span":{"name":"sign_up"},"spans":[{"name":"sign_up"}]}

When we configure gotrue with:

      - GOTRUE_DISABLE_SIGNUP=true

Appflowy is not able to start at all

appflowy_cloud-1  | {"timestamp":"2024-05-09T11:38:20.383807Z","level":"ERROR","fields":{"error":"code: 403, msg:Signups not allowed for this instance, error_id: None"},"target":"gotrue::api","span":{"name":"sign_up"},"spans":[{"name":"sign_up"}]}
appflowy_cloud-1  | Error: Failed to initialize application state: code: 403, msg:Signups not allowed for this instance, error_id: None
appflowy_cloud-1  | 
appflowy_cloud-1  | Stack backtrace:
appflowy_cloud-1  |    0: anyhow::error::<impl anyhow::Error>::msg
appflowy_cloud-1  |    1: tokio::task::local::LocalSet::run_until::{{closure}}
appflowy_cloud-1  |    2: appflowy_cloud::main
appflowy_cloud-1  |    3: std::sys_common::backtrace::__rust_begin_short_backtrace
appflowy_cloud-1  |    4: main
appflowy_cloud-1  |    5: <unknown>
appflowy_cloud-1  |    6: __libc_start_main
appflowy_cloud-1  |    7: _start

To Reproduce Steps to reproduce the behavior:

  1. Start appflowy docker-compose.

Expected behavior User already exist, no error triggered.

Desktop (please complete the following information):

Additional context

ppluciennik commented 3 months ago

This patch appears to fix the startup issue:

diff --git a/src/application.rs b/src/application.rs
index 69e093c..0bc9470 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -320,6 +320,7 @@ async fn setup_admin_account(
     Err(err) => {
       if let app_error::gotrue::GoTrueError::Internal(err) = err {
         match (err.code, err.msg.as_str()) {
+          (403, "Signups not allowed for this instance") => Ok(gotrue_admin),
           (400, "User already registered") => {
             info!("Admin user already registered");
             Ok(gotrue_admin)
henri9813 commented 3 months ago

Hello,

Should we not just check if the admin account exists before trying to create it and wait an error ?

ppluciennik commented 3 months ago

That's better option in my opinion.

Killian-Aidalinfo commented 3 months ago

Hello, I have the same problem, is there a way around it?

henri9813 commented 3 months ago

I will learn rust and then propose a patch if no one do this :)