Create the first superadmin from DOCWELL_ADMIN_EMAIL on start
When DOCWELL_ADMIN_EMAIL and DOCWELL_ADMIN_PASSWORD are set (and optionally DOCWELL_ADMIN_NAME), docwell-server creates that account as superadmin on start while the instance has no accounts. Once any account exists it changes nothing, so restarts never reset the password or a role changed in the admin panel. Without them, the first sign-up still wins. Pass the variables through every compose file, document them in the .env examples and the configuration, access and quick-start guides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9be8be156
commit
3c7403ddf9
27 files changed
+239
-3
No files matched your search
@@ -86,6 +86,19 @@ func run(log *slog.Logger) error {
|
||||
OAuthRedirects: []string{cfg.WebURL + "/oauth/callback", "docwell://oauth/callback"},
|
||||
})
|
||||
settingsSvc.SetOAuthCallback(cfg.WebURL + "/oauth/callback")
|
||||
if cfg.AdminEmail != "" {
|
||||
adminCtx, cancelAdmin := context.WithTimeout(context.Background(), time.Minute)
|
||||
created, err := authSvc.EnsureSuperadmin(adminCtx, cfg.AdminEmail, cfg.AdminPassword, cfg.AdminName)
|
||||
cancelAdmin()
|
||||
switch {
|
||||
case err != nil:
|
||||
return fmt.Errorf("create superadmin from DOCWELL_ADMIN_EMAIL: %w", err)
|
||||
case created:
|
||||
log.Info("created superadmin from DOCWELL_ADMIN_EMAIL", "email", cfg.AdminEmail)
|
||||
default:
|
||||
log.Info("accounts already exist; DOCWELL_ADMIN_EMAIL left unused")
|
||||
}
|
||||
}
|
||||
auditLog := audit.New(db, log)
|
||||
defer auditLog.Close()
|
||||
hooks := webhooks.New(db, log, webhooks.Options{AllowLocal: cfg.WebhooksAllowLocal})
|
||||
|
||||
Reference in new issue
Block a user