Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/app/src/features/auth/auth-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { Link, useSearch } from "@tanstack/react-router";
import { api } from "factorize-api-client";
import { messageOf, refreshIdentity } from "./session";
import { SettingsLayout } from "../settings/navigation";

export type AuthMode = "login" | "signup" | "reset" | "verify" | "verify-request" | "password";
const titles: Record<AuthMode, string> = {
login: "Sign in to Factorize", signup: "Create your Factorize account", reset: "Reset password",
verify: "Verify your email", "verify-request": "Resend verification email", password: "Change password",
};
export function AuthScreen({ mode }: { mode: AuthMode }) {
export function AuthScreen({ mode, inSettingsLayout = false }: { mode: AuthMode; inSettingsLayout?: boolean }) {
const search = useSearch({ strict: false }) as { token?: string; returnTo?: string; connection?: string; expired?: boolean };
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
Expand Down Expand Up @@ -59,10 +60,9 @@ export function AuthScreen({ mode }: { mode: AuthMode }) {
function submit(event: FormEvent) { event.preventDefault(); setNotice(""); mutation.mutate(); }
const showEmail = mode !== "password" && mode !== "verify" && !resetCompletion;
const showPassword = mode === "login" || mode === "signup" || mode === "password" || resetCompletion;
return (
<Page className="my-8 flex-none max-w-md rounded-2xl border border-stone-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-8">
<p className="text-xs font-semibold uppercase tracking-widest text-factorize-700 dark:text-factorize-500">Your software factory</p>
<h1 className="my-6 text-2xl font-semibold">{titles[mode]}</h1>
const content = <>
{!inSettingsLayout && <p className="text-xs font-semibold uppercase tracking-widest text-factorize-700 dark:text-factorize-500">Your software factory</p>}
{!inSettingsLayout && <h1 className="my-6 text-2xl font-semibold">{titles[mode]}</h1>}
{search.connection && <p>Connecting {continuation.data?.clientName ?? "your MCP client"}. After verification, review its permissions and choose Allow or Deny.</p>}
{(continuation.error || search.expired) && <p role="alert">{continuation.error?.message ?? "Your MCP request has expired. Start a new connection from your client."}</p>}
{mode === "login" && <p className="my-4">New to Factorize? <Link className="font-semibold text-factorize-700 underline dark:text-factorize-500" to="/auth/signup" search={{ connection: search.connection, returnTo: search.returnTo }}>Create an account to connect your client</Link>.</p>}
Expand All @@ -79,6 +79,6 @@ export function AuthScreen({ mode }: { mode: AuthMode }) {
{mode === "login" && <><Link to="/auth/signup" search={{ connection: search.connection, returnTo: search.returnTo }}>Create an account</Link><Link to="/auth/password-reset" search={{ connection: search.connection, returnTo: search.returnTo }}>Forgot password?</Link></>}
<Link to="/auth/verify/request" search={{ connection: search.connection, returnTo: search.returnTo }}>Resend verification</Link>
</nav>
</Page>
);
</>;
return inSettingsLayout ? <SettingsLayout title={titles[mode]}>{content}</SettingsLayout> : <Page className="my-8 flex-none max-w-md rounded-2xl border border-stone-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-8">{content}</Page>;
}
4 changes: 2 additions & 2 deletions packages/app/src/features/auth/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const validateSearch = (input: Record<string, unknown>): { token?: string; retur
returnTo: typeof input.returnTo === "string" ? input.returnTo : undefined,
});
export function authRoutes(rootRoute: AnyRootRoute) {
function route(path: "/auth/login" | "/auth/signup" | "/auth/password-reset" | "/auth/verify" | "/auth/verify/request" | "/settings/password", mode: AuthMode) {
function route(path: "/auth/login" | "/auth/signup" | "/auth/password-reset" | "/auth/verify" | "/auth/verify/request", mode: AuthMode) {
return createRoute({
getParentRoute: () => rootRoute, path, validateSearch,
component: () => <Screen mode={mode} />,
Expand All @@ -23,5 +23,5 @@ export function authRoutes(rootRoute: AnyRootRoute) {
} } : {}),
});
}
return [route("/auth/login", "login"), route("/auth/signup", "signup"), route("/auth/password-reset", "reset"), route("/auth/verify", "verify"), route("/auth/verify/request", "verify-request"), route("/settings/password", "password")];
return [route("/auth/login", "login"), route("/auth/signup", "signup"), route("/auth/password-reset", "reset"), route("/auth/verify", "verify"), route("/auth/verify/request", "verify-request")];
}
4 changes: 3 additions & 1 deletion packages/app/src/features/settings/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createRoute, lazyRouteComponent, redirect, type AnyRootRoute } from "@tanstack/react-router";
import { sessionQuery } from "../auth/session";
import { queryClient } from "../../shared/query-client";
import { AuthScreen } from "../auth/auth-screen";
export function settingsRoutes(root: AnyRootRoute) {
const guard = async ({ location }: { location: { href: string } }) => { if (!(await queryClient.ensureQueryData(sessionQuery)).authenticated) throw redirect({ to: "/auth/login", search: { returnTo: location.href, token: undefined } }); };
return [createRoute({ getParentRoute: () => root, path: "/settings/integrations", beforeLoad: guard, component: lazyRouteComponent(() => import("./integrations"), "Integrations") }), createRoute({ getParentRoute: () => root, path: "/settings", beforeLoad: guard, component: lazyRouteComponent(() => import("./integrations"), "Integrations") }), createRoute({ getParentRoute: () => root, path: "/settings/targets", beforeLoad: guard, component: lazyRouteComponent(() => import("./targets"), "Targets") }),
createRoute({ getParentRoute: () => root, path: "/settings/api-keys", beforeLoad: guard, component: lazyRouteComponent(() => import("./api-keys"), "ApiKeys") }),
createRoute({ getParentRoute: () => root, path: "/settings/authorized-clients", beforeLoad: guard, component: lazyRouteComponent(() => import("./authorized-clients"), "AuthorizedClients") })];
createRoute({ getParentRoute: () => root, path: "/settings/authorized-clients", beforeLoad: guard, component: lazyRouteComponent(() => import("./authorized-clients"), "AuthorizedClients") }),
createRoute({ getParentRoute: () => root, path: "/settings/password", beforeLoad: guard, component: () => <AuthScreen mode="password" inSettingsLayout /> })];
}
17 changes: 17 additions & 0 deletions packages/app/test/auth.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ test("password route redirects an unauthenticated viewer to login with a local r
await context.close();
});

test("authenticated password route shows settings navigation with the active password link", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
const page = await context.newPage();
await page.route("**/api/v1/session", route => route.fulfill({ json: {
authenticated: true, user: { id: "owner-a", email: "owner@example.test" },
workspace: { id: "workspace-a", name: "Workspace", role: "owner" }, capabilities: [],
} }));
await page.goto(origin + "/settings/password");
const settings = page.getByRole("navigation", { name: "Settings" });
await settings.getByRole("link", { name: "Integrations", exact: true }).waitFor();
const password = settings.getByRole("link", { name: "Change password", exact: true });
await password.waitFor();
assert.equal(await password.getAttribute("aria-current"), "page");
assert.match(await password.getAttribute("class"), /bg-factorize-50/);
await context.close();
});

test("logout refreshes session identity and removes the account display", async () => {
const context = await browser.newContext();
const page = await context.newPage();
Expand Down
Loading