fix(governance): ask for the public URL during owner setup (#2076)

This commit is contained in:
sam committed 2026-11-27 02:33:15 +11:00
1 parent 24a3efcf60
commit 6b4ff8101a
11 files changed
+147 -147

No files matched your search

+52 -54
View File
@@ -6,38 +6,34 @@ import { computed, ref } from "vue";
import { Card } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { api, describeError } from "@/lib/api";
import { api, ApiError, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { passkeysAvailable, useAccountsStore, usePasskey } from "./accounts";
const accounts = useAccountsStore();
const recovery = ref(false);
const recoveryCode = ref("");
const organisation = ref("");
const workspace = ref("Default");
const publicURL = ref("");
const currentOrigin = window.location.origin;
const name = ref("");
const email = ref("");
const password = ref("");
const busy = ref(false);
const error = ref("");
const notice = ref("");
const ownerCreated = ref(false);
const setup = computed(() => accounts.status?.setup_required === true);
const passkey = computed(() => passkeysAvailable(accounts.status?.public_url ?? ""));
// Setup asks one thing at a time: the organisation, then its first workspace,
// then the account that owns it.
const ACCOUNT_STEP = 3;
const step = ref(1);
async function submit() {
if (setup.value && !recovery.value && step.value < ACCOUNT_STEP) {
step.value += 1;
return;
}
busy.value = true;
error.value = "";
notice.value = "";
try {
if (ownerCreated.value) {
await openAccountWhenReady();
return;
}
if (recovery.value) {
await api.recoverAccount(email.value, recoveryCode.value, password.value);
recovery.value = false;
@@ -46,35 +42,46 @@ async function submit() {
return;
}
if (setup.value) {
// The instance URL is the address the operator already reached, and it
// stays editable under Settings, authentication once passkeys exist.
await api.setupAccount({
organisation_name: organisation.value,
workspace_name: workspace.value,
public_url: window.location.origin,
public_url: publicURL.value.trim(),
display_name: name.value,
email: email.value,
password: password.value,
});
} else {
await api.signIn(email.value, password.value);
password.value = "";
ownerCreated.value = true;
await openAccountWhenReady();
return;
}
await api.signIn(email.value, password.value);
password.value = "";
window.location.assign(
setup.value
? "/account?welcome=1"
: new URLSearchParams(window.location.search).has("reauth")
? "/account"
: "/",
);
window.location.assign(new URLSearchParams(window.location.search).has("reauth") ? "/account" : "/");
} catch (cause) {
error.value = describeError(cause, errors.common.unknown);
await accounts.load();
if (!ownerCreated.value) await accounts.load();
} finally {
busy.value = false;
}
}
async function openAccountWhenReady(): Promise<void> {
const deadline = Date.now() + 15_000;
// Setup creates the owner before Archie opens its operational routes.
for (;;) {
try {
await api.passkeys();
window.location.assign("/account?welcome=1");
return;
} catch (cause) {
if (!(cause instanceof ApiError) || cause.status !== 404) throw cause;
if (Date.now() >= deadline) {
throw new Error("Archie hasn't finished starting. Try opening your account again.");
}
await new Promise((resolve) => window.setTimeout(resolve, 500));
}
}
}
async function signInPasskey() {
busy.value = true;
error.value = "";
@@ -95,37 +102,28 @@ async function signInPasskey() {
<div class="mb-2"><Logo /></div>
<h1 class="text-title font-medium">
{{
setup
? step === 1
? "Set up your organisation"
: step === 2
? "Create your first workspace"
: "Create your account"
: recovery
? "Recover your account"
: "Sign in"
setup ? "Set up Archie" : recovery ? "Recover your account" : "Sign in"
}}
</h1>
<form class="mt-6 space-y-4" @submit.prevent="submit">
<template v-if="setup && step === 1">
<Label class="block space-y-1.5 text-label" for="organisation">Name<Input id="organisation" v-model="organisation" autocomplete="organization" required maxlength="200" /></Label>
</template>
<template v-else-if="setup && step === 2">
<Label class="block space-y-1.5 text-label" for="workspace">Name<Input id="workspace" v-model="workspace" required maxlength="200" /></Label>
</template>
<template v-else>
<Label v-if="setup" class="block space-y-1.5 text-label" for="account-name">Your name<Input id="account-name" v-model="name" autocomplete="name" required maxlength="200" /></Label>
<Label class="block space-y-1.5 text-label" for="account-email">Email<Input id="account-email" v-model="email" type="email" autocomplete="username" :spellcheck="false" required /></Label>
<Label v-if="recovery" class="block space-y-1.5 text-label" for="recovery-code">Recovery code<Input id="recovery-code" v-model="recoveryCode" autocomplete="off" required /></Label>
<Label class="block space-y-1.5 text-label" for="account-password">{{ recovery ? "New password" : "Password" }}<Input id="account-password" v-model="password" type="password" :autocomplete="setup || recovery ? 'new-password' : 'current-password'" :minlength="setup || recovery ? 15 : undefined" maxlength="1024" required /></Label>
<p v-if="setup" class="text-caption text-fg-muted">At least 15 characters.</p>
</template>
<div v-if="ownerCreated" class="mt-6 space-y-4">
<p role="status">Your account is ready. Archie is starting.</p>
<Alert v-if="error" variant="destructive"><AlertDescription>{{ error }}</AlertDescription></Alert>
<Button v-if="!busy" class="w-full" @click="submit">Open your account</Button>
</div>
<form v-else class="mt-6 space-y-4" @submit.prevent="submit">
<div v-if="setup" class="flex flex-col gap-1.5">
<Label for="instance-url">Instance URL</Label>
<Input id="instance-url" v-model="publicURL" type="url" :placeholder="currentOrigin" aria-describedby="instance-url-help" required />
<p id="instance-url-help" class="text-caption text-fg-muted">Use the public address people will sign in at. You can't change it after adding a passkey.</p>
</div>
<Label v-if="setup" class="block space-y-1.5 text-label" for="account-name">Your name<Input id="account-name" v-model="name" autocomplete="name" required maxlength="200" /></Label>
<Label class="block space-y-1.5 text-label" for="account-email">Email<Input id="account-email" v-model="email" type="email" autocomplete="username" :spellcheck="false" required /></Label>
<Label v-if="recovery" class="block space-y-1.5 text-label" for="recovery-code">Recovery code<Input id="recovery-code" v-model="recoveryCode" autocomplete="off" required /></Label>
<Label class="block space-y-1.5 text-label" for="account-password">{{ recovery ? "New password" : "Password" }}<Input id="account-password" v-model="password" type="password" :autocomplete="setup || recovery ? 'new-password' : 'current-password'" :minlength="setup || recovery ? 15 : undefined" maxlength="1024" required /></Label>
<p v-if="setup" class="text-caption text-fg-muted">At least 15 characters.</p>
<Alert v-if="error" variant="destructive"><AlertDescription>{{ error }}</AlertDescription></Alert>
<Alert v-if="notice" class="mt-4"><AlertDescription>{{ notice }}</AlertDescription></Alert>
<div class="flex gap-2">
<Button v-if="setup && step > 1" type="button" variant="outline" :disabled="busy" @click="step -= 1">Back</Button>
<Button type="submit" class="flex-1" :disabled="busy">{{ busy ? "Please wait…" : setup ? (step === ACCOUNT_STEP ? "Create account" : "Continue") : recovery ? "Reset password" : "Sign in" }}</Button>
</div>
<Button type="submit" class="w-full" :disabled="busy">{{ busy ? "Please wait…" : setup ? "Create account" : recovery ? "Reset password" : "Sign in" }}</Button>
</form>
<div v-if="!setup && !recovery" class="mt-4 flex flex-col gap-2">
<Button v-if="passkey" variant="outline" :disabled="busy" @click="signInPasskey">Sign in with a passkey</Button>