Repository navigation
fix(add): smooth the rough edges found while documenting add - #274
Merged
Merged
Conversation
Default --api-url by ecosystem (and the entry's listen call), list the searched folders from the detector's own list, print working credentialed CORS for Go, Axum and Django, install python-dotenv for FastAPI and Django and load it in the printed code, give React the AuthRoutes sign-in step, and remove the em dashes from user-facing text. Closes #271
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #271
Branched from
main, separate from #273 (the Compose project name for #270). The two touch nearby lines inadd.ts,helpTopics.ts,add.test.tsand the README, but they merge cleanly in either order. I checked by merging both locally: 1324 tests passed andtscwas clean.The six items
--api-urldefaults by ecosystem. When the backend's.envhas noPORT,addreads the port from the entry file's listen call:app.listen(4000),http.ListenAndServe(":8081", ...),r.Run(":9000"),e.Start(":1323"),Addr: "...:7070",TcpListener::bind("0.0.0.0:3000"),SocketAddr::from(([..], 4001)), oruvicorn.run(..., port=8001). If there is none, it falls back toDEFAULT_BACKEND_PORTS: 3000 for Node, 8000 for FastAPI and Django (the uvicorn andrunserverdefaults), and 8080 for Go and Rust.:8080. Gin'sRun()with no address also defaults to 8080.PORT3000, but they are scaffolded byinit, notadd, and they setPORTin.env, which still wins.seamless help addand the README document the order.searchedDirsText()indetect.tsbuilds its text fromCANDIDATE_DIRSandWORKSPACE_PARENTS, the same arrays detection walks. The "Found no backend" error and theaddhelp both use it, soapp/(plusweb/,client/andfrontend/in the error) now appear. The README is static, so a test checks that the README contains the generated list in backticks, and another checks that each listed folder is where detection actually finds a backend.templates/api/ginandtemplates/api/axumin seamless-templatesmain:withCORSnet/http middleware. It reflects an allowedOrigin, setsAllow-Credentials, and answers preflight with 204. net/http serveswithCORS(mux), and chi usesr.Use(withCORS)ahead of the routes.middleware.CORSWithConfigwithAllowCredentials. It is in the echo module, so nothing new to install.CorsLayer(AllowOrigin::list,allow_credentials(true), mirrored headers). It is layered before the console is merged, so the same-origin console stays outside CORS, as in the starter. The install now also runscargo add tower-http --features cors.INSTALLED_APPS += ["corsheaders"],CorsMiddlewarefirst,CORS_ALLOWED_ORIGINSfromUI_ORIGINS,CORS_ALLOW_CREDENTIALS = True), anddjango-cors-headersis installed with the adapter.UI_ORIGINS, falling back to the detected web origin, the same as Express, Fastify and FastAPI..env. I did what the FastAPI starter does: installpython-dotenvand callload_dotenv(). FastAPI and Django now installpython-dotenv, and the printed code callsload_dotenv()before readingos.environ. The hint says so and no longer mentionsuvicorn --env-file. The pip note now says "them" for the extra packages.templates/web/react-vite/src/App.tsxand the@seamless-auth/reactREADME:<App />inBrowserRouterandAuthProviderat the entry.AuthRoutesfrom@seamless-auth/react/routesbehind aSignInguest guard onpath="*", plus aRequireAuthguard for signed-in pages. It goes insrc/App.tsx|jsx|jswhen that file exists, otherwise the entry. JavaScript apps get the same code without theReactNodetype.react-router-dom(an optional peer of the binding that the routes need) is installed when the app does not have it.seamless <command> --helpheader is nowseamless add (seamless v0.23.0). Other user-facing em dashes insrcare fixed too: the top-level help tagline, theverifysummary lines, and the admin dashboard prompt labels ininit. So are two code comments and the testdescribetitles. A test now fails if any file undersrccontains an em dash.Tests
detect.test.ts:searchedDirsTextmatches the folders detection searches;backendListenPortdefaults per ecosystem and reads each listen pattern; Reactrouterfile and thereact-router-dompeer.snippets.test.ts: CORS per Go router, Axum (layer before the console), Django;load_dotenv()before the first env read; new install lines for Rust, FastAPI, Django.webSnippets.test.ts: React steps, files, TS vs JS, router peer.add.test.ts: API URL default for FastAPI, Django, Go, Axum; listen-call port andPORTprecedence; the no-backend error names every searched folder; React install andAuthRoutesoutput.help.test.ts: help names the folders and ports, generated lines stay within the help width, README matches the folder list, no em dash insrc.Verification
npm run build,npm test(63 files, 1309 passed, 4 skipped),npm run check:types-current,npm run check:templates-pin, and the pre-commit coverage run (lines 99.23%) all pass.I ran the built CLI (
add --local --yes --email=you@example.com </dev/null, installs run for real) against these scratch projects. For each one I pasted the printed code into the app and compiled or ran it::3000npm install @seamless-auth/react react-router-domtsc --noEmiton api and web,vite build:8000uv add "seamless-auth[fastapi]>=0.2" python-dotenvpython -c "import main"with an empty environment (soload_dotenv()supplied every value)uvicorn main:app: preflight fromlocalhost:5173gotallow-originandallow-credentials:8080go get seamless-auth-go(v0.2.0)go vet,go buildgo vet:3001, read fromTcpListener::bindcargo add seamless-auth,cargo add tower-http --features corscargo check,cargo build/console/served without them:8000uv add "seamless-auth[django]>=0.2" python-dotenv django-cors-headersmanage.py check(no issues)runserver: preflight gotallow-originandallow-credentials;GET /api/mereturned 401Not run: Express CORS at runtime (its snippet is unchanged), and Fastify (unchanged).
Docs to update after release (fells-code/seamless-auth-docs)
src/content/docs/operate/add-to-existing-app.mdx:python-dotenv, plusdjango-cors-headersfor Django. L30 (Rust row): alsotower-httpwith thecorsfeature.react-router-domif missing.--api-urldefaults. Drop the "FastAPI and Django usually listen on 8000, so pass--api-url" workaround, and describe the new order (PORT, the listen call, then 3000 for Node, 8000 for Python, 8080 for Go and Rust).$ cd web && npm install @seamless-auth/react react-router-dom.react-router-domfor React..envstays by hand.CorsLayeris printed andtower-httpis installed.python-dotenv.load_dotenv()and python-dotenv is installed. Drop the--env-fileand "pass--api-urlif uvicorn is not on port 3000" text; keep therequirements.txtnote for pip.python-dotenvanddjango-cors-headers.load_dotenv()are now printed.BrowserRouterplusAuthProviderat the entry, thenAuthRouteswith signed-in and signed-out guards insrc/App.src/content/docs/reference/cli-commands.mdx:cargo add seamless-authandcargo add tower-http --features cors.python-dotenv, anddjango-cors-headersfor Django.@seamless-auth/react, plusreact-router-domif missing.--api-urlrow): default isPORTfrom.env, else the entry's listen port, else 3000 (Node), 8000 (FastAPI, Django), 8080 (Go, Rust).