Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit daa7caf

Browse files
fix(console,auth): the login and register pages offer sign-up only where the audience posture admits it (objectui#11691) (#11703)
Fixes #11691 Clause-②: yes ## What this changes `/api/v1/auth/config` states the sign-up rule as two keys: `emailPassword.disableSignUp` (the hard off switch) and `features.audiencePosture` (who may self-register). The server deliberately does not force the first from the second: under `invite_only` its sign-up route still admits a pending invitee. The console read only the first, so under the default `invite_only` posture `/login` offered "Sign up" and `/register` refused the finished form with `403 SELF_REGISTRATION_CLOSED`. Both console pages now decide through one shared function, `decideSignUpOffer` in the new `apps/console/src/pages/auth/signUpOffer.ts`: | config | `/login` | `/register` | |---|---|---| | `disableSignUp: true` | no "Sign up", as objectui#11634 does | bounces to `/login` as before, invitation redirects included | | posture `open` or `email_domain` | unchanged | unchanged | | posture `invite_only`, reached from an invitation (`?redirect=/accept-invitation/ID`) | "Sign up", carrying the redirect | the form | | posture `invite_only`, deployment with no owner yet (`bootstrap-status` answers `hasOwner: false`) | "Sign up" | the form | | posture `invite_only`, otherwise | no "Sign up" | says "Self-registration is not open on this environment. Ask an administrator for an invitation." before any field, with a Sign in link | | no `audiencePosture` key (older server) | `disableSignUp` alone decides, as before | same | | a posture value outside the spec vocabulary | read as closed | read as closed | - `@object-ui/auth`: `AuthPublicConfig.features` declares `audiencePosture?: AudiencePosture` (the type from `@objectstack/spec/system`), beside `tenancyPosture`. The README's server-feature-flags section says how to read it beside `disableSignUp`. - `@object-ui/auth`'s `@objectstack/spec` floor moves from `^17.0.0` to `^17.3.0`. The published `types.d.ts` now references `AudiencePosture`, which 17.0.0 to 17.2.0 do not export, and `check:spec-floors` names that exact finding when the old floor is restored (see Evidence). The matching `pnpm-lock.yaml` change is one specifier line, the shape PR #11623 used for plugin-form. - The posture predicate is restated locally (`audienceAdmitsUninvitedSignUp`) rather than imported at runtime. This follows the `postureHasOrgWall` precedent in app-shell's `useTenancyPosture.ts`, because the login and register pages are in the console's eager closure. A parity test imports the spec's `audiencePermitsSelfRegistration` and `AUDIENCE_POSTURES` and asserts agreement for every declared posture. - No new i18n key. The register page's explanation reuses `auth.register.errors.selfRegistrationClosed`, which is the refusal's own copy, plus the existing title and "Already have an account? Sign in" keys. ### One addition beyond the triage direction: the first-owner window Triage's direction (comment 6010280240) names two cases that keep the generic sign-up under `invite_only`: an `open` or `email_domain` posture, and an invitation redirect. Measured, a third case is load-bearing: - The server's `decideAudienceAdmission` admits a bootstrap creation under every posture, with the comment "a fresh install must never lock its operator out". - The objectstack self-hosting guide's first-run step is "Open the deployment's root URL and sign up". - The console has no automatic route to `/setup`: nothing in `apps/console/src` or app-shell navigates there. Without the window, an unseeded fresh deployment on the default posture would land its operator on a login page with no way to create the first account. So under a closed posture the pages ask `GET /api/v1/auth/bootstrap-status` through `useBootstrapStatus` from `components/setupEntry.ts` (reused, not edited), and keep "Sign up" while `hasOwner` is false. The probe runs only when the posture is closed and the visitor is not an invitee. `open`, `email_domain` and older servers make no extra request, which is pinned. There is no server change and no new key. If the seat prefers the literal direction, removing the `context.bootstrap === 'fresh'` line from `decideSignUpOffer`, together with its two pins, reverts it. ## Premises measured 1. **Key path and vocabulary.** `features.audiencePosture` is emitted by `getPublicConfig` in objectstack's `auth-manager.ts` (origin/main `01e0f71a`) and by the published `@objectstack/plugin-auth@17.6.0` tarball (`audiencePosture: audience.posture`). The spec's closed vocabulary is `AUDIENCE_POSTURES` = `invite_only`, `email_domain`, `open` (`@objectstack/spec/system`, installed 17.6.0). Its `audiencePermitsSelfRegistration` is true for `email_domain` and `open` only. `getAuthConfig` unwraps the `{ success, data }` envelope, so the pages read `cfg.features.audiencePosture`. 2. **Older server.** For a config without the key, `decideSignUpOffer` returns the pre-change answer and makes no bootstrap probe. This is pinned for both pages. 3. **Invitation redirect.** No marker is needed. `DefaultAcceptInvitationPage` bounces a signed-out visitor to `/login?redirect=` plus the router path `/accept-invitation/ID`, and `/login` already forwards `redirect` to `/register`. The pages recognise the `/accept-invitation/` prefix followed by a non-empty id, and `AcceptInvitationPage.tsx` is not edited. Recognition is an affordance only: a non-invitee who types the URL by hand still meets the server's refusal, which the form renders localized. 4. **Clause-②.** The published surface that moved is `@object-ui/auth`'s `dist/types.d.ts`, with a new optional `features.audiencePosture` member and a new type import from `@objectstack/spec/system`, plus the package's spec floor. No locale key and no export was added or removed. ## Evidence All results are at branch head `efcf1ea` unless another commit is named. - **New pins.** `apps/console/src/pages/auth/__tests__/signUpFollowsPosture-11691.test.tsx`: 16 passed. A real `AuthProvider` runs over a real `createAuthClient` against a stub server. The end-to-end case clicks "Sign up" from `/login` with an invitation redirect, fills the form, and reads the `/sign-up/email` request body. - **Ablation.** Run on committed `387c36b` in WRAP mode through objectstack's `scripts/ablation-replace.mjs`; each restore was proven as blob equal to HEAD with an empty `git diff HEAD`. - With the decision ignoring the posture (the pre-fix behaviour): 3 failed, 13 passed. The failures are the decision table, "/login under invite_only offers no generic Sign up", and "/register explains instead of rendering the form". - With the invitation exception deleted: 3 failed, 13 passed. The failures are the decision table, "/login offers Sign up to an invitation redirect", and "an invitation redirect reaches a working registration". - **Type reverse check.** A probe file assigning `audiencePosture: 'invite-only'` turns console `tsc` red with TS2820 on that value only; the `'invite_only'` line beside it compiles. With the probe removed, console `type-check` is green. - **Floor reverse check.** Restoring `"@objectstack/spec": "^17.0.0"` makes `check:spec-floors` report `@object-ui/auth [floor-too-low] packages/auth/dist/types.d.ts references AudiencePosture from @objectstack/spec/system, which @objectstack/spec@17.0.0 does not export`. The floor was then restored. - **Union at `efcf1ea`.** `pnpm exec vitest run apps/console/src/pages/auth/ packages/auth/` plus the four `App.*` and `internalFormShell` tests that mock these pages: 43 files and 367 tests passed. - **Type-check and lint.** `pnpm --filter @object-ui/auth run type-check` exits 0. `pnpm --filter @object-ui/console run type-check` exits 0, after building the `@object-ui/console^...` closure (34 tasks). `lint` for both packages reports 0 errors; its warnings are on pre-existing lines only. Type-check and lint ran at `8e12c74`, whose sources are byte-identical to `efcf1ea`: that later commit adds only the changeset. - **Root gates at `efcf1ea`, each exit 0:** `check:new-line-citations` (0 new), `check:control-bytes`, `check:changeset-claims`, `check:pending-changeset-literals`, `check:i18n-keys`, `check:i18n-dead-keys`, `check:test-path-roots`, `check:readme-exports`, `check:spec-symbols`, `check:phantom-deps`, `check:lockfile-integrity`, `check:lockfile-dedupe`, `check:unreferenced-sources`, `check:installed-pin-claims`, `check:vi-mock-specifiers`, `check:spec-floors`, `check:eager-closure`, `node scripts/check-changeset-no-major.mjs` and `node scripts/check-changeset-presence.mjs`. - `check:readme-exports` needs `@object-ui/cli` and `@object-ui/plugin-ai` built, so they were built first. - `check:eager-closure` ran on a fresh console `vite build`. - `check-governed-queue-guard.mjs --test` answers NOT GOVERNED for all 9 paths. - **Left to CI:** the repo-wide `pnpm lint`, the full `pnpm test`, and `check:i18n-drift` (no `en` value changed). ## Acceptance notes - **The same defect, outside this claim.** app-shell's published `DefaultLoginPage` and `DefaultRegisterPage` read only `disableSignUp`. A throwaway probe, not committed, measured it with `audiencePosture: 'invite_only'` and `disableSignUp: false`: `DefaultLoginPage` offers "Sign up" to `/register`, and `DefaultRegisterPage` renders the full form. Its control leg (`disableSignUp: true`) hides the link. `examples/console-starter/src/App.tsx` routes both pages. This goes to the seat for its own card and is not edited here, because it is a different package with its own verification surface. - **Doc drift, noted only.** objectstack's `content/docs/permissions/authentication.mdx` says "The Console's root route uses it to choose between `/login` (normal) and `/setup` (first-run owner creation)", but no console code navigates to `/setup`. Carrier: none. - **Files outside the claim's listed surface, declared here.** `signUpOffer.ts` is a new file beside the two pages. `packages/auth/package.json` and the one-line `pnpm-lock.yaml` change are there for floor honesty, under objectui#5793's ruling. `packages/auth/README.md` is there because AGENTS.md rule 2 asks for docs. - **Untouched, as triage directed:** the settings follow-up (`signup_enabled` versus `audience_posture` on the objectstack settings page). --- _Generated by [Claude Code](https://claude.ai/code/session_01FngvPpdrnhHMdHHq6vwwju)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3409fe8 commit daa7caf

9 files changed

Lines changed: 611 additions & 21 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/console': minor
3+
'@object-ui/auth': minor
4+
---
5+
6+
The console's login and register pages offer a generic sign-up only where the server would accept one (objectui#11691). `/api/v1/auth/config` states the sign-up rule as two keys, `emailPassword.disableSignUp` and `features.audiencePosture`, and the server deliberately does not force the first from the second: under `invite_only` its sign-up route still admits a pending invitee. The pages read only `disableSignUp`, so under the default `invite_only` posture `/login` offered "Sign up" and `/register` refused the finished form with `SELF_REGISTRATION_CLOSED`.
7+
8+
Both pages now read both keys:
9+
10+
- `disableSignUp: true` still hides sign-up outright, invitation links included.
11+
- Under `open` or `email_domain`, nothing changes.
12+
- Under `invite_only`, `/login` shows no "Sign up" link. A visitor who arrived from an invitation (`?redirect=/accept-invitation/ID`, the signed-out bounce of the invitation page) still gets the link, and `/register` still renders the form for them. A deployment with no owner yet (`GET /api/v1/auth/bootstrap-status` answers `hasOwner: false`) keeps the link for its first owner, because the server admits the first account under every posture.
13+
- Otherwise `/register` says that self-registration is not open and points back to sign-in, before any field is filled in, instead of refusing the submitted form.
14+
- A server that sends no `audiencePosture` is answered as before, by `disableSignUp` alone. A posture value the console does not recognise reads as closed.
15+
16+
**Clause-②: yes.** `@object-ui/auth`'s published `AuthPublicConfig.features` gains an optional `audiencePosture` member, typed as `@objectstack/spec`'s `AudiencePosture`. The package's `@objectstack/spec` range moves from `^17.0.0` to `^17.3.0`, the first release that declares that type. No export, prop or i18n key is added or removed: the register page's explanation reuses the existing `auth.register.errors.selfRegistrationClosed` sentence.

‎apps/console/src/pages/auth/LoginPage.tsx‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212
* - Post-login orchestration: replay the original `/oauth2/authorize`
1313
* request, auto-select the user's single organization, or honour a
1414
* safe `?redirect=` target.
15-
* - Hides the "Sign up" link when the server reports
16-
* `emailPassword.disableSignUp === true`.
15+
* - Offers the "Sign up" link only when the server would accept a sign-up
16+
* from this visitor: never under `emailPassword.disableSignUp === true`,
17+
* and under an audience posture closed to strangers (`invite_only`) only
18+
* for an invitation redirect or a deployment with no owner yet — see
19+
* `./signUpOffer` (objectui#11691).
1720
*/
1821

1922
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2023
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
2124
import { useAuth, LoginForm, AuthErrorBanner } from '@object-ui/auth';
25+
import type { AuthPublicConfig } from '@object-ui/auth';
2226
import { useObjectTranslation } from '@object-ui/i18n';
2327
import { Card } from '@object-ui/components';
2428
import { signInRefusalMessages } from '@object-ui/app-shell';
2529
import { AuthLayout } from './AuthLayout';
2630
import { followOauthAuthorize } from './followAuthorize';
31+
import { decideSignUpOffer, isInvitationRedirect, needsBootstrapProbe } from './signUpOffer';
32+
import { useBootstrapStatus } from '../../components/setupEntry';
2733
// Was module-private here; lifted to a shared module so `SetupPage` (whose
2834
// first-run exits went without it) and `RegisterPage` (which had copied it)
2935
// share ONE implementation — objectui#4181. Behaviour here is unchanged.
@@ -58,7 +64,10 @@ export function LoginPage() {
5864
getAuthConfig,
5965
} = useAuth();
6066

61-
const [signUpDisabled, setSignUpDisabled] = useState(false);
67+
// The public auth config, once read — `null` until then (and after a failed
68+
// read), which `decideSignUpOffer` answers as "offer the link", the
69+
// behaviour before the config is known.
70+
const [authConfig, setAuthConfig] = useState<AuthPublicConfig | null>(null);
6271
// Dev-only seeded-admin hint (15.1 third-party eval): the runtime seeds
6372
// admin@objectos.ai on an empty dev DB, but nothing on this page said so —
6473
// new users clicked "Sign up" and landed in an empty non-admin workspace.
@@ -100,6 +109,15 @@ export function LoginPage() {
100109
if (!isLoading) setHasBootstrapped(true);
101110
}, [isLoading]);
102111

112+
// objectui#11691 — whether this visitor is offered "Sign up". The bootstrap
113+
// probe runs only when the posture is closed to strangers and the visitor
114+
// did not come from an invitation; see `./signUpOffer`.
115+
const invitationRedirect = isInvitationRedirect(redirect);
116+
const bootstrap = useBootstrapStatus(
117+
hasBootstrapped && !user && needsBootstrapProbe(authConfig, invitationRedirect),
118+
);
119+
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
120+
103121
// Detect SSO hand-off so we can surface the relying-party host.
104122
const ssoTarget = useMemo(() => {
105123
if (typeof window === 'undefined') return null;
@@ -127,14 +145,14 @@ export function LoginPage() {
127145
// eslint-disable-next-line react-hooks/exhaustive-deps
128146
}, []);
129147

130-
// Read public auth config once to know whether sign-up is gated off and
148+
// Read public auth config once to know whether sign-up is offered and
131149
// whether the dev-seeded admin credentials should be surfaced.
132150
useEffect(() => {
133151
let cancelled = false;
134152
getAuthConfig()
135153
.then((cfg) => {
136154
if (cancelled) return;
137-
setSignUpDisabled(cfg?.emailPassword?.disableSignUp === true);
155+
setAuthConfig(cfg ?? null);
138156
const seed = (cfg as { devSeedAdmin?: { email?: unknown; password?: unknown } } | null)
139157
?.devSeedAdmin;
140158
setDevSeedAdmin(
@@ -296,7 +314,7 @@ export function LoginPage() {
296314
) : null}
297315
<Card className="border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95">
298316
<LoginFormCard
299-
registerUrl={signUpDisabled ? undefined : registerUrl}
317+
registerUrl={signUpOffer === 'form' ? registerUrl : undefined}
300318
redirect={redirect}
301319
/>
302320
</Card>

‎apps/console/src/pages/auth/RegisterPage.tsx‎

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*
88
* - Bounces to `/login` if `emailPassword.disableSignUp === true`
99
* (defense-in-depth; the server-side gate is the source of truth).
10+
* - Under an audience posture closed to strangers (`invite_only`), shows
11+
* the form only to an invitation redirect or on a deployment with no
12+
* owner yet, and otherwise explains that registration is by invitation
13+
* BEFORE the form — see `./signUpOffer` (objectui#11691).
1014
* - Routes to `/verify-email-prompt` when the server requires email
1115
* verification before sign-in, and carries `?redirect=` into the
1216
* verification mail's link so it survives the inbox (objectui#10893).
@@ -16,12 +20,15 @@
1620

1721
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
1822
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
19-
import { useAuth, RegisterForm } from '@object-ui/auth';
23+
import { useAuth, RegisterForm, AuthFormHeader, AUTH_LINK_CLASS } from '@object-ui/auth';
24+
import type { AuthPublicConfig } from '@object-ui/auth';
2025
import { useObjectTranslation } from '@object-ui/i18n';
2126
import { Card } from '@object-ui/components';
2227
import { signUpRefusalMessages } from '@object-ui/app-shell';
2328
import { AuthLayout } from './AuthLayout';
2429
import { followOauthAuthorize } from './followAuthorize';
30+
import { decideSignUpOffer, isInvitationRedirect, needsBootstrapProbe } from './signUpOffer';
31+
import { useBootstrapStatus } from '../../components/setupEntry';
2532
// Was a second module-private copy of LoginPage's helper; both now share one
2633
// implementation — objectui#4181. Behaviour here is unchanged.
2734
import { withConsoleBase, withConsoleBaseRootRelative } from '../../utils/consoleBase';
@@ -53,7 +60,10 @@ export function RegisterPage() {
5360
getAuthConfig,
5461
} = useAuth();
5562

56-
const [signUpDisabled, setSignUpDisabled] = useState<boolean | null>(null);
63+
// `null` until the public auth config has been read; then `{ config }`,
64+
// whose `config` is `null` when the read failed — answered as "offer the
65+
// form", leaving the server's own gate as the source of truth.
66+
const [configRead, setConfigRead] = useState<{ config: AuthPublicConfig | null } | null>(null);
5767
const [autoSelectingOrg, setAutoSelectingOrg] = useState(false);
5868
// Fire the OAuth hand-off fetch at most once (see LoginPage).
5969
const ssoHandoffStartedRef = useRef(false);
@@ -67,26 +77,40 @@ export function RegisterPage() {
6777
if (!isLoading) setHasBootstrapped(true);
6878
}, [isLoading]);
6979

70-
// Probe public auth config — bounce to /login if sign-up is gated off.
80+
// Probe public auth config — what this visitor is offered follows from it.
7181
useEffect(() => {
7282
let cancelled = false;
7383
getAuthConfig()
7484
.then((cfg) => {
75-
if (cancelled) return;
76-
const disabled = cfg?.emailPassword?.disableSignUp === true;
77-
setSignUpDisabled(disabled);
78-
if (disabled) {
79-
const search = redirect ? `?redirect=${encodeURIComponent(redirect)}` : '';
80-
navigate(`/login${search}`, { replace: true });
81-
}
85+
if (!cancelled) setConfigRead({ config: cfg ?? null });
8286
})
8387
.catch(() => {
84-
if (!cancelled) setSignUpDisabled(false);
88+
if (!cancelled) setConfigRead({ config: null });
8589
});
8690
return () => {
8791
cancelled = true;
8892
};
89-
}, [getAuthConfig, navigate, redirect]);
93+
}, [getAuthConfig]);
94+
95+
// objectui#11691 — the offer reads `disableSignUp` AND the audience posture;
96+
// the bootstrap probe runs only when the posture is closed to strangers and
97+
// the visitor did not come from an invitation. See `./signUpOffer`.
98+
const authConfig = configRead ? configRead.config : null;
99+
const invitationRedirect = isInvitationRedirect(redirect);
100+
const bootstrap = useBootstrapStatus(
101+
configRead !== null &&
102+
hasBootstrapped &&
103+
!user &&
104+
needsBootstrapProbe(authConfig, invitationRedirect),
105+
);
106+
const signUpOffer = decideSignUpOffer(authConfig, { invitationRedirect, bootstrap });
107+
108+
// Sign-up switched off — bounce to /login.
109+
useEffect(() => {
110+
if (signUpOffer !== 'closed') return;
111+
const search = redirect ? `?redirect=${encodeURIComponent(redirect)}` : '';
112+
navigate(`/login${search}`, { replace: true });
113+
}, [signUpOffer, navigate, redirect]);
90114

91115
// Post-signup orchestration mirrors LoginPage exactly.
92116
useEffect(() => {
@@ -132,7 +156,13 @@ export function RegisterPage() {
132156
switchOrganization,
133157
]);
134158

135-
if (signUpDisabled === null || (isLoading && !hasBootstrapped) || user) {
159+
if (
160+
configRead === null ||
161+
signUpOffer === 'closed' ||
162+
signUpOffer === 'pending' ||
163+
(isLoading && !hasBootstrapped) ||
164+
user
165+
) {
136166
return (
137167
<AuthLayout>
138168
<div className="flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground">
@@ -151,6 +181,36 @@ export function RegisterPage() {
151181
? withConsoleBaseRootRelative(redirect)
152182
: undefined;
153183

184+
// objectui#11691 — registration here is by invitation only. Say so BEFORE
185+
// the form instead of refusing the finished form with
186+
// `SELF_REGISTRATION_CLOSED`; the sentence is that refusal's own copy.
187+
if (signUpOffer === 'by-invitation') {
188+
return (
189+
<AuthLayout formWidth="md">
190+
<Card className="border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95">
191+
<div
192+
data-testid="register-by-invitation"
193+
className="mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]"
194+
>
195+
<AuthFormHeader
196+
title={t('auth.register.title', { defaultValue: 'Create an account' })}
197+
description={t('auth.register.errors.selfRegistrationClosed', {
198+
defaultValue:
199+
'Self-registration is not open on this environment. Ask an administrator for an invitation.',
200+
})}
201+
/>
202+
<p className="px-8 text-center text-sm text-muted-foreground">
203+
{t('auth.register.hasAccountText', { defaultValue: 'Already have an account?' })}{' '}
204+
<Link to={loginUrl} className={AUTH_LINK_CLASS}>
205+
{t('auth.register.signInText', { defaultValue: 'Sign in' })}
206+
</Link>
207+
</p>
208+
</div>
209+
</Card>
210+
</AuthLayout>
211+
);
212+
}
213+
154214
return (
155215
<AuthLayout formWidth="md">
156216
<Card className="border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95">

0 commit comments

Comments
 (0)