feat(example-fastify-web-call-api): add web app calling an API example#88
feat(example-fastify-web-call-api): add web app calling an API example#88frederikprijck wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesA new Fastify web example authenticates users with Auth0, obtains access tokens, calls a protected API, renders the result, and includes integration tests, environment configuration, documentation, and CI coverage. Fastify web API example
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Browser
participant FastifyApp
participant Auth0
participant ResourceServer
Browser->>FastifyApp: Request /call-api
FastifyApp->>Auth0: Check session and request access token
Auth0-->>FastifyApp: Return access token
FastifyApp->>ResourceServer: GET /api/private with Bearer token
ResourceServer-->>FastifyApp: Return protected response
FastifyApp-->>Browser: Render API response
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b136121 to
bf3aa54
Compare
19da61c to
75f5422
Compare
Add a runnable example mirroring the express example-express-web-call-api: a Fastify web app that logs the user in, requests an access token for the configured audience, and calls the example-fastify-api resource server on the user's behalf via getAccessToken(). Also add PORT env support to example-fastify-api so it can run on 3001 alongside this web app on 3000, and link the new example from the root README and llms.txt.
Add a vitest suite for the web-call-api example that mocks Auth0 (discovery, JWKS, token) and the downstream API with msw, then drives the full login and /call-api flow via fastify.inject() — no live services. Refactor the example into an exported buildApp() factory so the app can be driven by the test without binding a port, starting the server only when run directly. Add a 'Build and Test Examples' workflow that builds each example (and runs the web-call-api tests), mirroring the auth0-express examples CI. Also add a build script to example-fastify-api so CI can verify it compiles.
75f5422 to
bb69fd1
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/example-fastify-web-call-api/src/index.ts`:
- Around line 61-67: Update hasSessionPreHandler so the unauthenticated branch
returns the result of reply.redirect, and wrap request.url with
encodeURIComponent before interpolating it into the returnTo query parameter.
In `@examples/example-fastify-web-call-api/views/layout.ejs`:
- Around line 24-47: Update the layout navigation links to determine the current
route and conditionally apply the active class and aria-current="page" only to
the matching item. Pass the current route into the EJS template from the
relevant render handlers and use it for the links in the layout template.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d35a5099-899c-4027-9d91-4bfe0cce6836
⛔ Files ignored due to path filters (1)
examples/example-fastify-web-call-api/public/img/auth0.pngis excluded by!**/*.png
📒 Files selected for processing (15)
.github/workflows/examples.ymlREADME.mdexamples/example-fastify-api/src/index.tsexamples/example-fastify-web-call-api/.env.exampleexamples/example-fastify-web-call-api/README.mdexamples/example-fastify-web-call-api/package.jsonexamples/example-fastify-web-call-api/src/index.spec.tsexamples/example-fastify-web-call-api/src/index.tsexamples/example-fastify-web-call-api/tsconfig.jsonexamples/example-fastify-web-call-api/views/api.ejsexamples/example-fastify-web-call-api/views/index.ejsexamples/example-fastify-web-call-api/views/layout.ejsexamples/example-fastify-web-call-api/views/private.ejsexamples/example-fastify-web-call-api/views/public.ejsllms.txt
- return reply.redirect and encodeURIComponent(request.url) in hasSessionPreHandler - drop hardcoded active/aria-current from nav links
Description
Adds a runnable
example-fastify-web-call-apiexample. It demonstrates a Fastify web app that:@auth0/auth0-fastify.audience(obtained at login).example-fastify-api) on the user's behalf usingfastify.auth0Client.getAccessToken({ request, reply }), then renders the response at/call-api.Supporting changes
example-fastify-api: addedPORTenv support (was hardcoded to3000) so it can run on3001alongside this web app on3000— matching whatexample-express-apialready does.README.mdandllms.txt: linked the new example.Summary by CodeRabbit
New Features
Documentation
.env.example.Tests
CI