auth: Register entry beside Sign in, behind a config switch that is off

config.registration {enabled, url}: off by default and in config.json. When on with a
http(s) url, the sign-in page shows Register (a link to the account service's own page)
with the consent sentence and its version, both read from trainingNotice.ts
(new TRAINING_NOTICE_VERSION shared with the room notice). /signed-up/ is the return
page: it says to follow the steps from the sign-up page and promises nothing about mail;
with the switch off it redirects to sign in. Off keeps the existing Register link.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-10 16:55:26 +00:00 • committed by Void
commit d14a504ccf
12 changed files with 167 additions and 11 deletions

View file

@ -5,12 +5,14 @@
"featuredCommunities": {
"openAsDefault": false,
"spaces": ["#gamecult:gamecult.org"],
"rooms": [
"#tuwunel:grin.hu",
"#free-software-movement:matrix.org",
"#gentoo:matrix.org"
],
"servers": ["activematrixrooms.com", "matrixrooms.info", "matrix.org", "mozilla.org", "unredacted.org"]
"rooms": ["#tuwunel:grin.hu", "#free-software-movement:matrix.org", "#gentoo:matrix.org"],
"servers": [
"activematrixrooms.com",
"matrixrooms.info",
"matrix.org",
"mozilla.org",
"unredacted.org"
]
},
"hashRouter": {
@ -24,5 +26,10 @@
"dings": {
"enabled": false
},
"registration": {
"enabled": false,
"url": ""
}
}

View file

@ -7,6 +7,11 @@ export type HashRouterConfig = {
basename?: string;
};
export type RegistrationConfig = {
enabled?: boolean;
url?: string;
};
export type ClientConfig = {
defaultHomeserver?: number;
homeserverList?: string[];
@ -26,6 +31,10 @@ export type ClientConfig = {
// Per-Mind notification earcons (src/app/features/dings). Off unless `enabled: true`.
dings?: DingsConfig;
// The sign-up entry on the sign-in page. Off unless `enabled` is true; `url` is the account
// service's own registration page (a value, never a route this client invents).
registration?: RegistrationConfig;
// Dev preview only: the build answers a pretend homeserver in-page (src/preview-demo).
previewDemo?: boolean;
};

View file

@ -9,7 +9,7 @@ import {
} from 'react-router-dom';
import { ClientConfig } from '../hooks/useClientConfig';
import { AuthLayout, Login, Register, ResetPassword } from './auth';
import { AuthLayout, Login, Register, ResetPassword, SignedUp } from './auth';
import {
DIRECT_PATH,
DESK_PATH,
@ -18,6 +18,7 @@ import {
LOGIN_PATH,
INBOX_PATH,
REGISTER_PATH,
SIGNED_UP_PATH,
RESET_PASSWORD_PATH,
SPACE_PATH,
_CREATE_PATH,
@ -105,6 +106,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
>
<Route path={LOGIN_PATH} element={<Login />} />
<Route path={REGISTER_PATH} element={<Register />} />
<Route path={SIGNED_UP_PATH} element={<SignedUp />} />
<Route path={RESET_PASSWORD_PATH} element={<ResetPassword />} />
</Route>

View file

@ -0,0 +1,22 @@
import { Box, Text, color } from 'folds';
import React from 'react';
import { useClientConfig } from '../../hooks/useClientConfig';
import { registrationEntry } from './registrationEntry';
// Beside Sign in. Nothing renders unless the config switch is on; the consent sentence and its
// version come from trainingNotice.ts, the same ones a room shows.
export function RegisterEntry() {
const config = useClientConfig();
const entry = registrationEntry(config);
if (!entry) return null;
return (
<Box direction="Column" gap="100" alignItems="Center">
<Text align="Center">
Do not have an account? <a href={entry.url}>Register</a>
</Text>
<Text size="T200" align="Center" style={{ color: color.SurfaceVariant.OnContainer }}>
{entry.notice} (notice version {entry.noticeVersion})
</Text>
</Box>
);
}

View file

@ -0,0 +1,24 @@
import { Box, Text } from 'folds';
import React from 'react';
import { Link, Navigate } from 'react-router-dom';
import { useClientConfig } from '../../hooks/useClientConfig';
import { getLoginPath } from '../pathUtils';
import { registrationEntry } from './registrationEntry';
// Where the account service sends a newcomer back. It promises nothing about mail or timing:
// the sign-up page said what happens next, and this page points back to it.
export function SignedUp() {
const config = useClientConfig();
if (!registrationEntry(config)) return <Navigate to={getLoginPath()} replace />;
return (
<Box direction="Column" gap="500">
<Text size="H2" priority="400">
You signed up
</Text>
<Text>Follow the steps from the sign-up page to finish. Then sign in here.</Text>
<Text>
<Link to={getLoginPath()}>Sign in</Link>
</Text>
</Box>
);
}

View file

@ -1,4 +1,5 @@
export * from './AuthLayout';
export * from './login';
export * from './register';
export * from './SignedUp';
export * from './reset-password';

View file

@ -9,6 +9,8 @@ import { PasswordLoginForm } from './PasswordLoginForm';
import { SSOLogin } from '../SSOLogin';
import { TokenLogin } from './TokenLogin';
import { OrDivider } from '../OrDivider';
import { RegisterEntry } from '../RegisterEntry';
import { registrationEntry } from '../registrationEntry';
import { getLoginPath, getRegisterPath, withSearchParam } from '../../pathUtils';
import { usePathWithOrigin } from '../../../hooks/usePathWithOrigin';
import { LoginPathSearchParams } from '../../paths';
@ -37,7 +39,8 @@ const useLoginSearchParams = (searchParams: URLSearchParams): LoginPathSearchPar
export function Login() {
const server = useAuthServer();
const { hashRouter, previewDemo } = useClientConfig();
const config = useClientConfig();
const { hashRouter, previewDemo } = config;
const { loginFlows } = useAuthFlows();
const [searchParams] = useSearchParams();
const loginSearchParams = useLoginSearchParams(searchParams);
@ -90,9 +93,13 @@ export function Login() {
<span data-spacing-node />
</>
)}
<Text align="Center">
Do not have an account? <Link to={getRegisterPath(server)}>Register</Link>
</Text>
{registrationEntry(config) ? (
<RegisterEntry />
) : (
<Text align="Center">
Do not have an account? <Link to={getRegisterPath(server)}>Register</Link>
</Text>
)}
</Box>
);
}

View file

@ -0,0 +1,47 @@
import { describe, expect, it } from 'vitest';
import { registrationEntry } from './registrationEntry';
import {
PREVIEW_NOTICE_TEXT,
TRAINING_NOTICE_TEXT,
TRAINING_NOTICE_VERSION,
} from '../../utils/trainingNotice';
import config from '../../../../config.json';
const url = 'https://accounts.example/register';
describe('registration entry', () => {
it('is hidden when the switch is absent or off', () => {
expect(registrationEntry({})).toBeUndefined();
expect(registrationEntry({ registration: { url } })).toBeUndefined();
expect(registrationEntry({ registration: { enabled: false, url } })).toBeUndefined();
});
it('ships off in config.json', () => {
expect(registrationEntry(config)).toBeUndefined();
expect(config.registration.enabled).toBe(false);
});
it('is hidden when the switch is on but the url is no web address', () => {
expect(registrationEntry({ registration: { enabled: true } })).toBeUndefined();
expect(registrationEntry({ registration: { enabled: true, url: '' } })).toBeUndefined();
expect(
registrationEntry({ registration: { enabled: true, url: '/register' } })
).toBeUndefined();
expect(
registrationEntry({ registration: { enabled: true, url: 'data:text/html,x' } })
).toBeUndefined();
});
it('reads the consent text and version from trainingNotice.ts', () => {
expect(registrationEntry({ registration: { enabled: true, url } })).toEqual({
url,
notice: TRAINING_NOTICE_TEXT,
noticeVersion: TRAINING_NOTICE_VERSION,
});
});
it('says the pretend sentence on the pretend server', () => {
const entry = registrationEntry({ previewDemo: true, registration: { enabled: true, url } });
expect(entry?.notice).toBe(PREVIEW_NOTICE_TEXT);
});
});

View file

@ -0,0 +1,25 @@
import type { ClientConfig } from '../../hooks/useClientConfig';
import { TRAINING_NOTICE_VERSION, trainingNoticeText } from '../../utils/trainingNotice';
export type RegistrationEntry = { url: string; notice: string; noticeVersion: number };
/**
* The sign-up entry the sign-in page may show: the account service's registration page, when the
* switch is on and the configured url is a plain http(s) address. Anything else is no entry. The
* consent sentence and its version are trainingNotice.ts's, the ones a room shows.
*/
export const registrationEntry = (config: ClientConfig): RegistrationEntry | undefined => {
const { enabled, url } = config.registration ?? {};
if (enabled !== true || typeof url !== 'string') return undefined;
try {
const { protocol } = new URL(url);
if (protocol !== 'https:' && protocol !== 'http:') return undefined;
} catch {
return undefined;
}
return {
url,
notice: trainingNoticeText(config.previewDemo),
noticeVersion: TRAINING_NOTICE_VERSION,
};
};

View file

@ -16,6 +16,7 @@ import {
INBOX_NOTIFICATIONS_PATH,
INBOX_PATH,
REGISTER_PATH,
SIGNED_UP_PATH,
RESET_PASSWORD_PATH,
ROOT_PATH,
SPACE_LOBBY_PATH,
@ -83,6 +84,8 @@ export const getRegisterPath = (server?: string): string => {
return generatePath(REGISTER_PATH, params);
};
export const getSignedUpPath = (): string => SIGNED_UP_PATH;
export const getResetPasswordPath = (server?: string): string => {
const params = server ? { server: encodeURIComponent(server) } : undefined;
return generatePath(RESET_PASSWORD_PATH, params);

View file

@ -17,6 +17,8 @@ export const REGISTER_PATH = '/register/:server?/';
export type ResetPasswordPathSearchParams = {
email?: string;
};
export const SIGNED_UP_PATH = '/signed-up/';
export const RESET_PASSWORD_PATH = '/reset-password/:server?/';
export const _CREATE_PATH = 'create/';

View file

@ -28,6 +28,13 @@ export const trainingNoticeText = (previewDemo?: boolean): string =>
* else is malformed. Absent or malformed in any way means no train line.
*/
export const MAX_NOTICE_VERSION = 4294967295;
/**
* The version of the notice wording above. Registration shows it with the text, and a room's
* notice event carries the same number, so one text has one version on both surfaces. Bump it
* with the wording and nowhere else.
*/
export const TRAINING_NOTICE_VERSION = 1;
export const ROOM_NOTICE_EVENT_TYPE = StateEvent.GameCultNotice;
export type RoomNotice = { version: number; scope: 'show' | 'study' | 'train' };