auth: sign-up return page renders; gamecult.org is the default homeserver
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m35s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m35s
/signed-up/ sat inside AuthLayout, which discovers a homeserver and sends paths it does not know to sign in, so it never rendered. The signed-out routes move to authRoutes.tsx with the return page beside the layout (its own card, no discovery); a test matches the real route table and renders the page. Drop the visible notice version from the entry (it stays in registrationEntry's data and tests) and the unused getSignedUpPath. clientDefaultServer falls back to gamecult.org, and the repo config.json lists it first and defaults to it; a config that names its own list (the production pin) is unaffected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8f31174da0
commit
137fb5a96c
9 changed files with 166 additions and 44 deletions
11
config.json
11
config.json
|
|
@ -1,6 +1,13 @@
|
|||
{
|
||||
"defaultHomeserver": 1,
|
||||
"homeserverList": ["converser.eu", "matrix.org", "mozilla.org", "unredacted.org", "xmr.se"],
|
||||
"defaultHomeserver": 0,
|
||||
"homeserverList": [
|
||||
"gamecult.org",
|
||||
"converser.eu",
|
||||
"matrix.org",
|
||||
"mozilla.org",
|
||||
"unredacted.org",
|
||||
"xmr.se"
|
||||
],
|
||||
"allowCustomHomeservers": true,
|
||||
"featuredCommunities": {
|
||||
"openAsDefault": false,
|
||||
|
|
|
|||
20
src/app/hooks/useClientConfig.test.ts
Normal file
20
src/app/hooks/useClientConfig.test.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { clientDefaultServer } from './useClientConfig';
|
||||
import config from '../../../config.json';
|
||||
|
||||
describe('default homeserver', () => {
|
||||
it('is gamecult.org when the config names none', () => {
|
||||
expect(clientDefaultServer({})).toBe('gamecult.org');
|
||||
expect(clientDefaultServer({ homeserverList: [] })).toBe('gamecult.org');
|
||||
});
|
||||
|
||||
it('is the listed server the config points at', () => {
|
||||
expect(
|
||||
clientDefaultServer({ homeserverList: ['chat.gamecult.org'], defaultHomeserver: 0 })
|
||||
).toBe('chat.gamecult.org');
|
||||
});
|
||||
|
||||
it('is gamecult.org in the repo config.json too', () => {
|
||||
expect(clientDefaultServer(config)).toBe('gamecult.org');
|
||||
});
|
||||
});
|
||||
|
|
@ -46,7 +46,7 @@ export function useClientConfig(): ClientConfig {
|
|||
}
|
||||
|
||||
export const clientDefaultServer = (clientConfig: ClientConfig): string =>
|
||||
clientConfig.homeserverList?.[clientConfig.defaultHomeserver ?? 0] ?? 'matrix.org';
|
||||
clientConfig.homeserverList?.[clientConfig.defaultHomeserver ?? 0] ?? 'gamecult.org';
|
||||
|
||||
export const clientAllowedServer = (clientConfig: ClientConfig, server: string): boolean => {
|
||||
const { homeserverList, allowCustomHomeservers } = clientConfig;
|
||||
|
|
|
|||
|
|
@ -9,16 +9,12 @@ import {
|
|||
} from 'react-router-dom';
|
||||
|
||||
import { ClientConfig } from '../hooks/useClientConfig';
|
||||
import { AuthLayout, Login, Register, ResetPassword, SignedUp } from './auth';
|
||||
import { authRoutes } from './auth/authRoutes';
|
||||
import {
|
||||
DIRECT_PATH,
|
||||
EXPLORE_PATH,
|
||||
HOME_PATH,
|
||||
LOGIN_PATH,
|
||||
INBOX_PATH,
|
||||
REGISTER_PATH,
|
||||
SIGNED_UP_PATH,
|
||||
RESET_PASSWORD_PATH,
|
||||
SPACE_PATH,
|
||||
_CREATE_PATH,
|
||||
_FEATURED_PATH,
|
||||
|
|
@ -56,7 +52,7 @@ import { ScreenSize } from '../hooks/useScreenSize';
|
|||
import { MobileFriendlyPageNav } from './MobileFriendly';
|
||||
import { ClientInitStorageAtom } from './client/ClientInitStorageAtom';
|
||||
import { ClientNonUIFeatures } from './client/ClientNonUIFeatures';
|
||||
import { AuthRouteThemeManager, UnAuthRouteThemeManager } from './ThemeManager';
|
||||
import { AuthRouteThemeManager } from './ThemeManager';
|
||||
import { ReceiveSelfDeviceVerification } from '../components/DeviceVerification';
|
||||
import { AutoRestoreBackupOnVerification } from '../components/BackupRestore';
|
||||
import { RoomSettingsRenderer } from '../features/room-settings';
|
||||
|
|
@ -87,26 +83,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
|||
return redirect(getLoginPath());
|
||||
}}
|
||||
/>
|
||||
<Route
|
||||
loader={() => {
|
||||
if (getFallbackSession()) {
|
||||
return redirect(getHomePath());
|
||||
}
|
||||
|
||||
return null;
|
||||
}}
|
||||
element={
|
||||
<>
|
||||
<AuthLayout />
|
||||
<UnAuthRouteThemeManager />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<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>
|
||||
{authRoutes()}
|
||||
|
||||
<Route
|
||||
loader={() => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export function RegisterEntry() {
|
|||
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})
|
||||
{entry.notice}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,54 @@
|
|||
import { Box, Text } from 'folds';
|
||||
import { Box, Header, Scroll, Text } from 'folds';
|
||||
import classNames from 'classnames';
|
||||
import React from 'react';
|
||||
import { Link, Navigate } from 'react-router-dom';
|
||||
import { useClientConfig } from '../../hooks/useClientConfig';
|
||||
import { getLoginPath } from '../pathUtils';
|
||||
import { registrationEntry } from './registrationEntry';
|
||||
import { AuthFooter } from './AuthFooter';
|
||||
import * as css from './styles.css';
|
||||
import * as PatternsCss from '../../styles/Patterns.css';
|
||||
import RatatoskrSVG from '../../../../public/res/svg/ratatoskr.svg';
|
||||
import { LogoMark } from '../../components/logo/logoMark.css';
|
||||
|
||||
// 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.
|
||||
// the sign-up page said what happens next, and this page points back to it. It has its own card
|
||||
// because AuthLayout looks up a homeserver first and sends paths it does not know to sign in.
|
||||
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>
|
||||
<Scroll variant="Background" visibility="Hover" size="300" hideTrack>
|
||||
<Box
|
||||
className={classNames(css.AuthLayout, PatternsCss.BackgroundDotPattern)}
|
||||
direction="Column"
|
||||
alignItems="Center"
|
||||
justifyContent="SpaceBetween"
|
||||
gap="400"
|
||||
>
|
||||
<Box direction="Column" className={css.AuthCard}>
|
||||
<Header className={css.AuthHeader} size="600" variant="Surface">
|
||||
<Box grow="Yes" direction="Row" gap="300" alignItems="Center">
|
||||
<img
|
||||
className={`${css.AuthLogo} ${LogoMark}`}
|
||||
src={RatatoskrSVG}
|
||||
alt="Ratatoskr logo"
|
||||
/>
|
||||
<Text size="H3">Ratatoskr</Text>
|
||||
</Box>
|
||||
</Header>
|
||||
<Box className={css.AuthCardContent} 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>
|
||||
</Box>
|
||||
<AuthFooter />
|
||||
</Box>
|
||||
</Scroll>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
40
src/app/pages/auth/authRoutes.tsx
Normal file
40
src/app/pages/auth/authRoutes.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react';
|
||||
import { Route, redirect } from 'react-router-dom';
|
||||
import { getFallbackSession } from '../../state/sessions';
|
||||
import { UnAuthRouteThemeManager } from '../ThemeManager';
|
||||
import { LOGIN_PATH, REGISTER_PATH, RESET_PASSWORD_PATH, SIGNED_UP_PATH } from '../paths';
|
||||
import { getHomePath } from '../pathUtils';
|
||||
import { AuthLayout } from './AuthLayout';
|
||||
import { Login } from './login';
|
||||
import { Register } from './register';
|
||||
import { ResetPassword } from './reset-password';
|
||||
import { SignedUp } from './SignedUp';
|
||||
|
||||
// The routes a signed-out visitor sees. The sign-up return page sits beside the layout, not in
|
||||
// it: the layout looks up a homeserver and sends any path it does not know to sign in.
|
||||
export const authRoutes = () => (
|
||||
<>
|
||||
<Route
|
||||
loader={() => (getFallbackSession() ? redirect(getHomePath()) : null)}
|
||||
element={
|
||||
<>
|
||||
<AuthLayout />
|
||||
<UnAuthRouteThemeManager />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Route path={LOGIN_PATH} element={<Login />} />
|
||||
<Route path={REGISTER_PATH} element={<Register />} />
|
||||
<Route path={RESET_PASSWORD_PATH} element={<ResetPassword />} />
|
||||
</Route>
|
||||
<Route
|
||||
path={SIGNED_UP_PATH}
|
||||
element={
|
||||
<>
|
||||
<SignedUp />
|
||||
<UnAuthRouteThemeManager />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
|
@ -16,7 +16,6 @@ import {
|
|||
INBOX_NOTIFICATIONS_PATH,
|
||||
INBOX_PATH,
|
||||
REGISTER_PATH,
|
||||
SIGNED_UP_PATH,
|
||||
RESET_PASSWORD_PATH,
|
||||
ROOT_PATH,
|
||||
SPACE_LOBBY_PATH,
|
||||
|
|
@ -83,8 +82,6 @@ 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);
|
||||
|
|
|
|||
51
src/app/pages/signedUpRoute.test.tsx
Normal file
51
src/app/pages/signedUpRoute.test.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import React from 'react';
|
||||
import { beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import { Route, createRoutesFromElements } from 'react-router-dom';
|
||||
import { StaticRouter, createStaticHandler } from 'react-router-dom/server';
|
||||
import { ClientConfigProvider } from '../hooks/useClientConfig';
|
||||
import type { ClientConfig } from '../hooks/useClientConfig';
|
||||
import { SIGNED_UP_PATH } from './paths';
|
||||
|
||||
const config: ClientConfig = { registration: { enabled: true, url: 'https://accounts.example/' } };
|
||||
|
||||
// The routes read localStorage when imported (settings atoms); the node environment has none.
|
||||
let authRoutes: typeof import('./auth/authRoutes').authRoutes;
|
||||
let SignedUp: typeof import('./auth').SignedUp;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('localStorage', {
|
||||
getItem: () => null,
|
||||
setItem: () => undefined,
|
||||
removeItem: () => undefined,
|
||||
});
|
||||
({ authRoutes } = await import('./auth/authRoutes'));
|
||||
({ SignedUp } = await import('./auth'));
|
||||
}, 120_000);
|
||||
|
||||
const matchPath = async (path: string) => {
|
||||
const { query } = createStaticHandler(createRoutesFromElements(<Route>{authRoutes()}</Route>));
|
||||
const context = await query(new Request(`http://localhost${path}`));
|
||||
if (context instanceof Response) {
|
||||
throw new Error(`redirected to ${context.headers.get('Location')}`);
|
||||
}
|
||||
return context.matches;
|
||||
};
|
||||
|
||||
describe('the sign-up return page in the real route table', () => {
|
||||
it('is its own route, outside AuthLayout (which would send it to sign in)', async () => {
|
||||
const matches = await matchPath(SIGNED_UP_PATH);
|
||||
// the pathless root, then the page itself: no layout route in between
|
||||
expect(matches?.map((m) => m.route.path)).toEqual([undefined, SIGNED_UP_PATH]);
|
||||
});
|
||||
|
||||
it('renders its words, not the sign-in form, when the switch is on', () => {
|
||||
const html = renderToString(
|
||||
<ClientConfigProvider value={config}>
|
||||
<StaticRouter location={SIGNED_UP_PATH}>
|
||||
<SignedUp />
|
||||
</StaticRouter>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
expect(html).toContain('Follow the steps from the sign-up page');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue