feat: let customers create an account from the sign-in page #32
|
|
@ -29,7 +29,7 @@ After the one-time [server setup](docs/STATIC-DEPLOYMENT.md), main-branch Drone
|
||||||
|
|
||||||
Storefront list returns only id/name/slug; details return prices/attributes/groups. The API has no product-media fields, so catalog cards use a generic branded placeholder rather than assigning local photos to unknown records. Existing marketing imagery remains intact.
|
Storefront list returns only id/name/slug; details return prices/attributes/groups. The API has no product-media fields, so catalog cards use a generic branded placeholder rather than assigning local photos to unknown records. Existing marketing imagery remains intact.
|
||||||
|
|
||||||
Addresses, cart/checkout, orders, catalog, access, stock, coupons and pricing tools are available after sign-in. Public registration and procurement/production/B2B tools remain subsequent phases. There is no contact-message endpoint; simulated success was replaced with an availability notice. Newsletter signup awaits consent/messaging flows.
|
Addresses, cart/checkout, orders, catalog, access, stock, coupons and pricing tools are available after sign-in. Customers can create their own account at `/workspace` (requires the backend `/auth/register` endpoint). There is no contact-message endpoint; simulated success was replaced with an availability notice. Newsletter signup awaits consent/messaging flows.
|
||||||
|
|
||||||
See [delivery phases](docs/PHASES.md) and [UAT evidence](docs/UAT-RESULTS.md).
|
See [delivery phases](docs/PHASES.md) and [UAT evidence](docs/UAT-RESULTS.md).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,4 +38,4 @@ Record the active and previous build/commit release IDs before rollout. The SSH
|
||||||
|
|
||||||
## Operational limits
|
## Operational limits
|
||||||
|
|
||||||
Pending intents exist only within the active browser session; reloading signs out and discards them. After interruption, inspect orders or the stock ledger before beginning a new intent. The backend currently has no live gateway/carrier, public registration or contact delivery. Staff catalog/role writes follow the backend's existing concurrency policy; coordinate overlapping administration edits. Never reinterpret finalized merchandise as proof of payment or fulfillment.
|
Pending intents exist only within the active browser session; reloading signs out and discards them. After interruption, inspect orders or the stock ledger before beginning a new intent. The backend currently has no live gateway/carrier or contact delivery; customer self-registration is available. Staff catalog/role writes follow the backend's existing concurrency policy; coordinate overlapping administration edits. Never reinterpret finalized merchandise as proof of payment or fulfillment.
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,21 @@ export async function login(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export async function register(
|
||||||
|
organizationId: string,
|
||||||
|
name: string,
|
||||||
|
email: string,
|
||||||
|
password: string,
|
||||||
|
) {
|
||||||
|
const organization = organizationSchema.parse(organizationId);
|
||||||
|
return parse(
|
||||||
|
sessionSchema,
|
||||||
|
await apiRequest("/auth/register", {
|
||||||
|
method: "POST",
|
||||||
|
body: { organizationId: organization, name, email, password },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
export async function getPrincipal(token: string) {
|
export async function getPrincipal(token: string) {
|
||||||
return parse(principalSchema, await apiRequest("/auth/me", { token }));
|
return parse(principalSchema, await apiRequest("/auth/me", { token }));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import {
|
||||||
login,
|
login,
|
||||||
organizationSchema,
|
organizationSchema,
|
||||||
parse,
|
parse,
|
||||||
|
register,
|
||||||
type Principal,
|
type Principal,
|
||||||
type Session,
|
type Session,
|
||||||
} from "./api";
|
} from "./api";
|
||||||
|
|
@ -29,6 +30,7 @@ const PlatformContext = createContext<{
|
||||||
principal: Principal | null;
|
principal: Principal | null;
|
||||||
scope: string;
|
scope: string;
|
||||||
signIn: (email: string, password: string) => Promise<void>;
|
signIn: (email: string, password: string) => Promise<void>;
|
||||||
|
signUp: (name: string, email: string, password: string) => Promise<void>;
|
||||||
signOut: () => Promise<void>;
|
signOut: () => Promise<void>;
|
||||||
notice: string;
|
notice: string;
|
||||||
clearSession: (notice?: string) => void;
|
clearSession: (notice?: string) => void;
|
||||||
|
|
@ -110,9 +112,15 @@ export function PlatformProvider({ children }: { children: ReactNode }) {
|
||||||
/* The in-memory setting still works. */
|
/* The in-memory setting still works. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function signIn(email: string, password: string) {
|
function signIn(email: string, password: string) {
|
||||||
|
return adopt(() => login(organization, email, password));
|
||||||
|
}
|
||||||
|
function signUp(name: string, email: string, password: string) {
|
||||||
|
return adopt(() => register(organization, name, email, password));
|
||||||
|
}
|
||||||
|
async function adopt(start: () => ReturnType<typeof login>) {
|
||||||
const version = ++generation.current;
|
const version = ++generation.current;
|
||||||
const next = await login(organization, email, password);
|
const next = await start();
|
||||||
try {
|
try {
|
||||||
const me = await getPrincipal(next.accessToken);
|
const me = await getPrincipal(next.accessToken);
|
||||||
if (
|
if (
|
||||||
|
|
@ -247,6 +255,7 @@ export function PlatformProvider({ children }: { children: ReactNode }) {
|
||||||
principal,
|
principal,
|
||||||
scope: principal ? `${principal.sessionId}:${accessRevision}` : "",
|
scope: principal ? `${principal.sessionId}:${accessRevision}` : "",
|
||||||
signIn,
|
signIn,
|
||||||
|
signUp,
|
||||||
signOut,
|
signOut,
|
||||||
notice,
|
notice,
|
||||||
clearSession,
|
clearSession,
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,25 @@ import "./workspace.css";
|
||||||
import { WorkspaceNavigation } from "@/components/WorkspaceShell";
|
import { WorkspaceNavigation } from "@/components/WorkspaceShell";
|
||||||
|
|
||||||
export default function WorkspacePage() {
|
export default function WorkspacePage() {
|
||||||
const { organization, principal, signIn, signOut, notice } = usePlatform();
|
const { organization, principal, signIn, signUp, signOut, notice } =
|
||||||
|
usePlatform();
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [error, setError] = useState<unknown>(null);
|
const [error, setError] = useState<unknown>(null);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.currentTarget;
|
const form = event.currentTarget;
|
||||||
const fields = new FormData(form);
|
const fields = new FormData(form);
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
const name = String(fields.get("name") ?? "");
|
||||||
const email = String(fields.get("email"));
|
const email = String(fields.get("email"));
|
||||||
const password = String(fields.get("password"));
|
const password = String(fields.get("password"));
|
||||||
form.reset();
|
form.reset();
|
||||||
try {
|
try {
|
||||||
await signIn(email, password);
|
await (creating
|
||||||
|
? signUp(name, email, password)
|
||||||
|
: signIn(email, password));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error);
|
setError(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -47,7 +52,7 @@ export default function WorkspacePage() {
|
||||||
<Container maxWidth="md">
|
<Container maxWidth="md">
|
||||||
<h1>Account Workspace</h1>
|
<h1>Account Workspace</h1>
|
||||||
<p className="workspace-intro">
|
<p className="workspace-intro">
|
||||||
Sign in with your approved Mani Candles account.
|
Sign in, or create a customer account to shop.
|
||||||
</p>
|
</p>
|
||||||
<Paper variant="outlined" className="workspace-panel">
|
<Paper variant="outlined" className="workspace-panel">
|
||||||
<ApiNotice error={error} />
|
<ApiNotice error={error} />
|
||||||
|
|
@ -68,7 +73,7 @@ export default function WorkspacePage() {
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
) : (
|
) : (
|
||||||
<p>No permissions assigned. Contact your administrator.</p>
|
<p>Customer account. Use your cart, addresses and orders below.</p>
|
||||||
)}
|
)}
|
||||||
<p className="workspace-intro">
|
<p className="workspace-intro">
|
||||||
Open a customer or administration tool below.
|
Open a customer or administration tool below.
|
||||||
|
|
@ -89,11 +94,20 @@ export default function WorkspacePage() {
|
||||||
backend.
|
backend.
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
{creating && (
|
||||||
|
<TextField
|
||||||
|
label="Full name"
|
||||||
|
name="name"
|
||||||
|
autoComplete="name"
|
||||||
|
required
|
||||||
|
inputProps={{ maxLength: 160 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<TextField
|
<TextField
|
||||||
label="Email address"
|
label="Email address"
|
||||||
name="email"
|
name="email"
|
||||||
type="email"
|
type="email"
|
||||||
autoComplete="username"
|
autoComplete={creating ? "email" : "username"}
|
||||||
required
|
required
|
||||||
inputProps={{ maxLength: 254 }}
|
inputProps={{ maxLength: 254 }}
|
||||||
/>
|
/>
|
||||||
|
|
@ -101,16 +115,36 @@ export default function WorkspacePage() {
|
||||||
label="Password"
|
label="Password"
|
||||||
name="password"
|
name="password"
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete={creating ? "new-password" : "current-password"}
|
||||||
required
|
required
|
||||||
inputProps={{ maxLength: 128 }}
|
helperText={creating ? "At least 15 characters." : undefined}
|
||||||
|
inputProps={{ minLength: creating ? 15 : 1, maxLength: 128 }}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={busy || !organization}
|
disabled={busy || !organization}
|
||||||
>
|
>
|
||||||
{busy ? "Signing in…" : "Sign in"}
|
{creating
|
||||||
|
? busy
|
||||||
|
? "Creating account…"
|
||||||
|
: "Create account"
|
||||||
|
: busy
|
||||||
|
? "Signing in…"
|
||||||
|
: "Sign in"}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="text"
|
||||||
|
type="button"
|
||||||
|
disabled={busy}
|
||||||
|
onClick={() => {
|
||||||
|
setCreating(!creating);
|
||||||
|
setError(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{creating
|
||||||
|
? "Already have an account? Sign in"
|
||||||
|
: "New customer? Create an account"}
|
||||||
</Button>
|
</Button>
|
||||||
<small>
|
<small>
|
||||||
Sessions stay in memory. Reloading or closing this page requires
|
Sessions stay in memory. Reloading or closing this page requires
|
||||||
|
|
|
||||||
|
|
@ -332,3 +332,19 @@ test("organization change cancels private scope and removes cached data", async
|
||||||
await waitFor(() => expect(h.result.current.scope).toBe(""));
|
await waitFor(() => expect(h.result.current.scope).toBe(""));
|
||||||
expect(h.client.getQueriesData({ queryKey: ["private"] })).toEqual([]);
|
expect(h.client.getQueriesData({ queryKey: ["private"] })).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("sign-up registers in the configured organization and adopts the new session", async () => {
|
||||||
|
const bodies: unknown[] = [];
|
||||||
|
vi.stubGlobal("fetch", vi.fn(async (url: string, options?: RequestInit) => {
|
||||||
|
if (url.endsWith("/auth/register")) {
|
||||||
|
bodies.push(JSON.parse(String(options?.body)));
|
||||||
|
return json(session, 201);
|
||||||
|
}
|
||||||
|
if (url.endsWith("/auth/me")) return json({ ...me, permissions: [] });
|
||||||
|
throw new Error(`Unexpected request ${url}`);
|
||||||
|
}));
|
||||||
|
const h = harness();
|
||||||
|
await act(() => h.result.current.signUp("Asha Buyer", "buyer@example.com", "a long enough password"));
|
||||||
|
expect(bodies).toEqual([{ organizationId: id, name: "Asha Buyer", email: "buyer@example.com", password: "a long enough password" }]);
|
||||||
|
expect(h.result.current.principal).toMatchObject({ userId: id, permissions: [] });
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue