diff --git a/packages/app/src/features/auth/auth-screen.tsx b/packages/app/src/features/auth/auth-screen.tsx index c63df028..c0f4bf63 100644 --- a/packages/app/src/features/auth/auth-screen.tsx +++ b/packages/app/src/features/auth/auth-screen.tsx @@ -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 = { 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(""); @@ -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 ( - -

Your software factory

-

{titles[mode]}

+ const content = <> + {!inSettingsLayout &&

Your software factory

} + {!inSettingsLayout &&

{titles[mode]}

} {search.connection &&

Connecting {continuation.data?.clientName ?? "your MCP client"}. After verification, review its permissions and choose Allow or Deny.

} {(continuation.error || search.expired) &&

{continuation.error?.message ?? "Your MCP request has expired. Start a new connection from your client."}

} {mode === "login" &&

New to Factorize? Create an account to connect your client.

} @@ -79,6 +79,6 @@ export function AuthScreen({ mode }: { mode: AuthMode }) { {mode === "login" && <>Create an accountForgot password?} Resend verification -
- ); + ; + return inSettingsLayout ? {content} : {content}; } diff --git a/packages/app/src/features/auth/routes.tsx b/packages/app/src/features/auth/routes.tsx index e48fe491..732291ec 100644 --- a/packages/app/src/features/auth/routes.tsx +++ b/packages/app/src/features/auth/routes.tsx @@ -11,7 +11,7 @@ const validateSearch = (input: Record): { 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: () => , @@ -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")]; } diff --git a/packages/app/src/features/settings/routes.tsx b/packages/app/src/features/settings/routes.tsx index 10cf9fbb..a3d14a1b 100644 --- a/packages/app/src/features/settings/routes.tsx +++ b/packages/app/src/features/settings/routes.tsx @@ -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: () => })]; } diff --git a/packages/app/test/auth.browser.test.mjs b/packages/app/test/auth.browser.test.mjs index 4b1e28e1..c206d2f4 100644 --- a/packages/app/test/auth.browser.test.mjs +++ b/packages/app/test/auth.browser.test.mjs @@ -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();