fix: address RWA test report bugs - #12
Merged
Merged
Conversation
…vars don't crash unrelated routes
…ion shape, context access pattern, deleteSession redirect warning, getAccessToken refresh prerequisites
…ENCE restrictions
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.
Summary
Fixes 9 bugs and 2 documentation gaps identified in the v1.0.0-beta.0 RWA test report.
stripIdTokenClaimsdid not removesid—sidis an OIDC session identifier sourced from the ID token but was absent fromSTRIP_CLAIMS. Added alongside the other stripped claims.RequireRolethrew during SSR, escapingAuth0ErrorBoundary— React error boundaries are client-only. Throwing during SSR bypassedAuth0ErrorBoundaryand surfaced at the framework root error handler. Fix: call the hook unconditionally then returnnullon the server and defer the role check to the client after hydration.defineRouteAuthcrashed with no parentauth0Middleware—context.get(auth0SessionContext)threw"No value found for context"when the key was never set and the default isundefined. Fix: added agetOptionalContexthelper that catches the error and returnsundefinedinstead.handleAuthreturned HTTP 500 forAuth0Errorsubclasses — React Router only respects status codes on thrownResponseobjects;Auth0Error.statusCodeis invisible to its error pipeline. Fix: wrapped the dispatch block inhandleAuthwith a try/catch that converts anyAuth0Errorto aResponsewith the correct status code.Standalone helpers ignored hooks on user's
Auth0Serverinstance —getSession,updateSession,deleteSession, etc. call an internalgetInstance()which creates a freshAuth0Serverwith no hooks. Fix: added a publicregisterAuth0Instance(instance)function so users can register their configured instance as the singleton.defineRouteAuthbundled server code into the client (145 kB) — Exporting bothhandleandmiddlewarefrom the samedefineRouteAuth()call caused React Router'ssplitRouteModulesto pull all server imports into the client bundle. Fix: extracteddefineRouteHandleinto a zero-importroute-handle.tsfile. Users should exporthandleviadefineRouteHandleandmiddlewareviadefineRouteAuthseparately.Auth0Serverconstructor threw at module load, crashing all routes — React Router loads all route modules at startup; aConfigurationErrorin any module cascaded to every route including public ones. Fix: deferred config validation and client initialisation to the first auth operation using lazy getters (config,serverClient,stateStore).defineRouteHandlestill behindbrowser: nullexport (RWA-009) — even after extraction,defineRouteHandlewas only exported via"./server"which has"browser": null, causing[commonjs--resolver] No known conditions for "./server" specifierin route files. Fix: re-exporteddefineRouteHandlefrom the root client bundle (@auth0/auth0-react-router) which has nobrowser: nullrestriction.deleteSessionfrom a protected action redirected to/page.data(RWA-012) — returning the baredeleteSessionresponse from a protected route action caused React Router to re-run the loader, which redirected to/auth/login?returnTo=/page.data(the internal data-fetch URL). Fix: added an optionalredirectToparameter —deleteSession(request, { redirectTo: '/' })— that returns a 302 directly, preventing the loader from re-running.getAccessTokentoken refresh prerequisites undocumented — silent refresh silently requires 3 Auth0 Dashboard steps plusoffline_accessin scope. Fix: added a "Calling APIs with access tokens" section to the README documenting all prerequisites and theTokenErrorhandling pattern.Test plan
stripIdTokenClaims— verifysidis absent from the returned user objectRequireRole— verifyAuth0ErrorBoundarycatches the 403 on an authenticated user missing a role (no root error boundary renders)defineRouteAuth— verify/define-route-auth-demoloads without HTTP 500 when no parentauth0Middlewareis presenthandleCallback— verifyGET /auth/callback?error=access_deniedreturns 400, not 500registerAuth0Instance— verifyonCallback/beforeSessionSavedhooks fire duringupdateSession/deleteSessionafter registering the instancedefineRouteHandle— verify the client bundle for a route that importsdefineRouteHandlefrom@auth0/auth0-react-routerbuilds withoutbrowser: nullerrorsAuth0Serverlazy init — verify a route with a missingAUTH0_DOMAINstarts without crashing and the error surfaces only on the first auth requestdeleteSession({ redirectTo })— verify a protected route action returns a clean 302 to the specified path with session cookies cleared