Sign-in and sign-up
Sign-in and sign-up pages use LoginForm, call the login API manh.run generates from app/auth.ts, store the session with signIn, show the Google button and show server errors on the form.
With app/auth.ts, manh.run generates the users table and the sign-in and sign-up APIs. The browser keeps the JWT and sends it with every API call. No cookies.
Shortcut: block_add("auth") adds app/auth.ts and the /login and /register pages shown here. Write your own screens only when you need a different layout.
// Sign-in: pro-components LoginForm with labels (accessibility + tests find fields by label); server errors show in `message`.
import { useState } from "react";
import { LoginForm, ProFormCheckbox, ProFormText } from "@ant-design/pro-components";
import { Alert, Flex, Typography, theme } from "antd";
import { AuditOutlined, LockOutlined, MailOutlined } from "@ant-design/icons";
export default function Page() {
const { token } = theme.useToken();
const [error, setError] = useState<string | null>(null);
return (
<Flex vertical justify="center" style={{ minHeight: "100vh", background: `linear-gradient(180deg, ${token.colorPrimaryBg} 0%, ${token.colorBgLayout} 45%)` }}>
<LoginForm
logo={<AuditOutlined style={{ fontSize: 40, color: token.colorPrimary }} />}
title="Purchase approvals"
subTitle="Request, approve and track purchase spending"
submitter={{ searchConfig: { submitText: "Sign in" } }}
initialValues={{ remember: true }}
message={error ? <Alert type="error" showIcon title={error} style={{ marginBottom: 24 }} /> : undefined}
actions={
<Flex vertical gap={8}>
<Typography.Text type="secondary">Don't have an account? <a>Sign up</a></Typography.Text>
{/* UI sample (Playground / docs): say clearly it's a demo so nobody types a real password. */}
<Typography.Text type="secondary" style={{ fontSize: 12 }}>UI demo — don't enter a real password; nothing is sent anywhere. Test password: 123456.</Typography.Text>
</Flex>
}
onFinish={async (v: { email: string; password: string }) => {
// Try it: any password other than "123456" shows the error a 401 from the server would.
if (v.password !== "123456") { setError("Incorrect email or password"); return false; }
setError(null);
return true;
}}
>
<ProFormText name="email" label="Email" placeholder="you@company.com" fieldProps={{ size: "large", prefix: <MailOutlined /> }} rules={[{ required: true, type: "email", message: "Enter a valid email" }]} />
<ProFormText.Password name="password" label="Password" placeholder="Password" fieldProps={{ size: "large", prefix: <LockOutlined />, autoComplete: "off" }} rules={[{ required: true, message: "Enter your password" }]} />
<div style={{ marginBlockEnd: 24 }}>
<ProFormCheckbox noStyle name="remember">Keep me signed in</ProFormCheckbox>
<a style={{ float: "right" }}>Forgot password?</a>
</div>
</LoginForm>
</Flex>
);
}
Build the "Sign in" screen for my app following the Manh UI playbook (framework_docs("pro")): Sign in: the pro-components LoginForm with labels (accessible + testable by label), server errors shown in `message`. Data comes from the app's API through useApiClient(); labels and fields follow my spec.Files of the sign-in flow
You write app/auth.ts and the UI pages. manh.run generates the server side; it isn’t stored in the project.
app/
├── login/page.tsx → /login (LoginForm)
├── register/page.tsx → /register (LoginForm, "Sign up" button)
├── components/role-guard.tsx guards pages by role
├── components/sso-buttons.tsx Google button, shown when app/auth.ts turns on providers
└── auth.ts roles, sign-up mode, providers
generated: POST /auth/login → api.auth.login(body)
POST /auth/register → api.auth.register(body)
GET /auth/providers → api.auth.providers()Sign-in and permissions covers app/auth.ts, access and the generated APIs. This page covers the UI.
Sign-in page
onFinish calls the login API. On success, signIn(...) stores the session and you navigate; on error, put the server’s message in message and return false so the form stays as it is.
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { LoginForm, ProFormText } from "@ant-design/pro-components";
import { Alert, Flex, Typography, theme } from "antd";
import { AuditOutlined, LockOutlined, MailOutlined } from "@ant-design/icons";
import { useApiClient } from "app/api";
import { signIn } from "app/hooks";
export default function Page() {
const api = useApiClient();
const nav = useNavigate();
const { token } = theme.useToken();
const [error, setError] = useState<string | null>(null);
return (
<Flex vertical justify="center" style={{ minHeight: "100vh", background: token.colorBgLayout }}>
<LoginForm
logo={<AuditOutlined style={{ fontSize: 40, color: token.colorPrimary }} />}
title="Purchase approvals"
subTitle="Request, approve, and track purchase spending"
submitter={{ searchConfig: { submitText: "Sign in" } }}
message={error ? <Alert type="error" showIcon title={error} style={{ marginBottom: 24 }} /> : undefined}
actions={<Typography.Text type="secondary">No account yet? <a onClick={() => nav("/register")}>Sign up</a></Typography.Text>}
onFinish={async (v) => {
try {
signIn(await api.auth.login(v));
nav("/");
return true;
} catch (e: any) {
setError(e?.response?.data?.message ?? "Could not sign in. Try again later.");
return false;
}
}}
>
<ProFormText name="email" label="Email" fieldProps={{ size: "large", prefix: <MailOutlined /> }}
rules={[{ required: true, type: "email", message: "Enter a valid email" }]} />
<ProFormText.Password name="password" label="Password" fieldProps={{ size: "large", prefix: <LockOutlined /> }}
rules={[{ required: true, message: "Enter your password" }]} />
</LoginForm>
</Flex>
);
}Sign-up page
The sign-up page reuses LoginForm and adds a name field and a password confirmation. The generated sign-up API needs a name of at least 2 characters and a password of at least 8; put the same rules on the form so users see errors before they submit.
<LoginForm
title="Create an account"
submitter={{ searchConfig: { submitText: "Sign up" } }}
message={error ? <Alert type="error" showIcon title={error} style={{ marginBottom: 24 }} /> : undefined}
actions={<Typography.Text type="secondary">Already have an account? <a onClick={() => nav("/login")}>Sign in</a></Typography.Text>}
onFinish={async ({ confirm, ...v }) => {
try { signIn(await api.auth.register(v)); nav("/"); return true; }
catch (e: any) { setError(e?.response?.data?.message ?? "Could not create the account"); return false; }
}}
>
<ProFormText name="name" label="Full name" fieldProps={{ size: "large" }} rules={[{ required: true }]} />
<ProFormText name="email" label="Email" fieldProps={{ size: "large" }} rules={[{ required: true, type: "email" }]} />
<ProFormText.Password name="password" label="Password" fieldProps={{ size: "large" }} rules={[{ required: true, min: 8 }]} />
<ProFormText.Password name="confirm" label="Confirm password" dependencies={["password"]} fieldProps={{ size: "large" }}
rules={[{ required: true }, ({ getFieldValue }) => ({
validator: (_, v) => (v === getFieldValue("password") ? Promise.resolve() : Promise.reject(new Error("Passwords do not match"))),
})]} />
</LoginForm>Google sign-in button
The auth block turns Google sign-in on: app/auth.ts has providers: ["google"]. Remove it for password-only sign-in. The /login and /register pages of the auth block show the button by themselves: app/components/sso-buttons.tsx reads api.auth.providers().
In your own screen, call signInWith:
import { Button } from "antd";
import { GoogleOutlined } from "@ant-design/icons";
import { signInWith } from "app/hooks";
// inside LoginForm, after the fields:
<Button block size="large" icon={<GoogleOutlined />}
onClick={async () => { await signInWith("google"); nav("/"); }}>
Sign in with Google
</Button>signInWith("google") opens a Google window and resolves once the user is signed in. If the browser blocks the window, the page goes to Google and comes back on its own.
Keep the session and sign out
After signIn(...), every call through useApiClient() or useApi() sends the Authorization: Bearer <token> header. To sign out, call signOut() and go to /login.
const { user, hasRole } = useSession() gives the signed-in user (id, name, email, role, avatarUrl) and re-renders on sign-in and sign-out. Use it to choose which menu items and buttons to show; the server still checks permissions with access. Outside React, use getUser().
Guard pages by role
AppShell already sends signed-out users to /login. To open a page to some roles only, wrap it in a component that reads useSession().
import { Navigate } from "react-router-dom";
import { useSession } from "app/hooks";
export function RoleGuard({ role, children }: { role: string; children: React.ReactNode }) {
const { hasRole } = useSession();
return hasRole(role) ? <>{children}</> : <Navigate to="/" replace />;
}When the API returns 401 (the token expired or the account was locked), the app signs the user out and goes to /login.
Good to know
- Keep a
labelon every field: screen readers and tests find fields by label. - Show server errors in the form’s
message, not in a toast. In antd v6,Alerttakestitle;messageis deprecated and logs a warning. - Don’t write the token to
localStorageyourself or add an axios interceptor, becausesignInhandles it.setAuthToken/getAuthTokenare low-level and rarely needed. - Don’t use
manh/oauthor cookie sessions. manh.run doesn’t support them: sign-in always uses a JWT sent in a header, and Google is turned on withprovidersinapp/auth.ts.
Next steps
- Sign-in and permissions —
app/auth.ts,accessand Google sign-in. - API handlers —
accessand the user in a handler. - Forms — ProForm fields, widths and validation.