mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-27 02:56:33 +00:00
fix: tenant switch auto-copies global admin into tenant users
isSetupComplete() now checks public.global_admins — if a global admin exists but tenant has no local users, copies admin into tenant's users table and marks setup complete. Prevents setup wizard on tenant switch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
65de42d495
commit
1dbb56752c
1 changed files with 18 additions and 1 deletions
|
|
@ -260,7 +260,24 @@ export class Repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async isSetupComplete(): Promise<boolean> {
|
async isSetupComplete(): Promise<boolean> {
|
||||||
return (await this.getSetupState()).is_complete && (await this.countUsers()) > 0;
|
const state = await this.getSetupState();
|
||||||
|
if (state.is_complete) return true;
|
||||||
|
if ((await this.countUsers()) > 0) return true;
|
||||||
|
// No local users — copy global admin into tenant if one exists.
|
||||||
|
const ga = await this._get<{ id: string; username: string; password_hash: string }>(
|
||||||
|
"SELECT id, username, password_hash FROM public.global_admins WHERE is_active = true LIMIT 1",
|
||||||
|
).catch(() => undefined);
|
||||||
|
if (ga) {
|
||||||
|
await this._run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, role, is_active)
|
||||||
|
VALUES (?, ?, ?, 'admin', true)
|
||||||
|
ON CONFLICT (id) DO NOTHING`,
|
||||||
|
[ga.id, ga.username, ga.password_hash],
|
||||||
|
);
|
||||||
|
await this.markSetupComplete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async markSetupComplete(): Promise<void> {
|
async markSetupComplete(): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue