-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reworks RSC server entries and route manifest building to deriv…
…e from routes and include if route info related to authentication (#10572) In furtherance if https://github.com/orgs/redwoodjs/projects/18/views/3?pane=issue&itemId=59049687 Currently @dac09 and I are thinking that to enforce authenticate during RSC rendering, we need to know if the entry request that renders the RSC component requires auth. This is not online how a graphQL operation is marked as requiring auth so that then the headers/cookie/credentials can be verified. This PR refactors 1. How server entries are built -- not from "processing the pages dir" (which is a deprecated function) but rather the routes ... and the page info for that route. Note here that a page can be used in multiple routes, so the auth info cannot really be determined here. 2. The route manifest building to include an isPrivate attribute. Now if some page, route request is being handler we might be able to check if it "isPrivate" and enforce auth. 3. Add `unauthenticated` property to the route manifest to show where the user would expect to be redirected to if not permitted. 4. Add `roles` to the route manifest Both of these efforts are just a little speculation, but need the ability to check to see if our approach is reasonable. FYI. The change in the RWRoute appears to have been an oversight from when the set was renamed from `Private` to `PrivateSet`. Now a route properly knows if it's private based on its parents. ## Tests Added to test to confirm that router can determine which routes are private. Note that fixtures are updated to favor `PrivateSet` over `Private` ... but the detection code still allows Private or PrivateSet. Tests added to check the name, path, unauthenticated and roles attributers of a RWRoute. ## Examples ### Entries The `web/dist/rsc/entries.mjs` builds correctly after refactor and app runs. ```js file="web/dist/rsc/entries.mjs" // client component mapping (dist/rsc -> dist/client) export const clientEntries = { "assets/rsc-AboutCounter.tsx-3.mjs": "assets/rsc-AboutCounter.tsx-3-CQh4fLws.mjs", "assets/rsc-UserExamplesCell.tsx-7.mjs": "assets/rsc-UserExamplesCell.tsx-7-BLKpK17-.mjs", "assets/rsc-Counter.tsx-1.mjs": "assets/rsc-Counter.tsx-1-BAFuKeO7.mjs", "assets/rsc-rsc-test.es.js-0.mjs": "assets/rsc-rsc-test.es.js-0-Bkk2qwSq.mjs", "assets/rsc-NewUserExample.tsx-4.mjs": "assets/rsc-NewUserExample.tsx-4-j-hB-OZ1.mjs", "assets/rsc-UserExample.tsx-8.mjs": "assets/rsc-UserExample.tsx-8-Dzll3QYc.mjs", "assets/rsc-UpdateRandomButton.tsx-2.mjs": "assets/rsc-UpdateRandomButton.tsx-2-BicEZIWn.mjs", "assets/rsc-EmptyUsersCell.tsx-5.mjs": "assets/rsc-EmptyUsersCell.tsx-5-BItXvbaj.mjs", "assets/rsc-NewEmptyUser.tsx-6.mjs": "assets/rsc-NewEmptyUser.tsx-6-DFmv_Yef.mjs", "assets/rsc-UserExamples.tsx-11.mjs": "assets/rsc-UserExamples.tsx-11-BrzStkU7.mjs", "assets/rsc-link.js-10.mjs": "assets/rsc-link.js-10-D1gHLB5z.mjs", "assets/rsc-CellErrorBoundary.js-13.mjs": "assets/rsc-CellErrorBoundary.js-13-C9r2jdob.mjs", "assets/rsc-index.js-12.mjs": "assets/rsc-index.js-12-BlDxo_As.mjs", "assets/rsc-navLink.js-9.mjs": "assets/rsc-navLink.js-9-BsKFwPvg.mjs" }; // server component mapping (src -> dist/rsc) export const serverEntries = { "HomePage": "assets/HomePage-BkyFywXn.mjs", "AboutPage": "assets/AboutPage-qKLtmepV.mjs", "MultiCellPage": "assets/MultiCellPage-Bb1xy2-X.mjs", "EmptyUserNewEmptyUserPage": "assets/EmptyUserNewEmptyUserPage-CRWGWYlQ.mjs", "EmptyUserEditEmptyUserPage": "assets/EmptyUserEditEmptyUserPage-DK14w5wt.mjs", "EmptyUserEmptyUserPage": "assets/EmptyUserEmptyUserPage-BDEfXSJo.mjs", "EmptyUserEmptyUsersPage": "assets/EmptyUserEmptyUsersPage-BZjgUE33.mjs", "UserExampleNewUserExamplePage": "assets/UserExampleNewUserExamplePage-CPG6dVwh.mjs", "UserExampleEditUserExamplePage": "assets/UserExampleEditUserExamplePage-BfvIJHxv.mjs", "UserExampleUserExamplePage": "assets/UserExampleUserExamplePage-Bwqi8NaS.mjs", "UserExampleUserExamplesPage": "assets/UserExampleUserExamplesPage-MQMjbAP0.mjs", "NotFoundPage": "assets/NotFoundPage-CstA1diQ.mjs", "__rwjs__ServerEntry": "entry.server.mjs" }; ``` ### Route Manifest ```tsx ... <Router> <Set wrap={NavigationLayout}> <Route path="/" page={HomePage} name="home" /> <PrivateSet unauthenticated="home"> <Route path="/about" page={AboutPage} name="about" /> </PrivateSet> <PrivateSet unauthenticated="home" roles="owner"> <Route path="/about-secret" page={AboutPage} name="aboutSecret" /> </PrivateSet> <PrivateSet unauthenticated="home" roles={['publisher', 'admin']}> <Route path="/about-secret-admin" page={AboutPage} name="aboutSecretAdmin" /> </PrivateSet> <Route path="/multi-cell" page={MultiCellPage} name="multiCell" /> ... ``` builds .. notice the about routes are private. ```json { "/": { "name": "home", "bundle": null, "matchRegexString": "^/$", "pathDefinition": "/", "hasParams": false, "routeHooks": null, "redirect": null, "relativeFilePath": "pages/HomePage/HomePage.tsx", "isPrivate": false }, "/about": { "name": "about", "bundle": null, "matchRegexString": "^/about$", "pathDefinition": "/about", "hasParams": false, "routeHooks": null, "redirect": null, "relativeFilePath": "pages/AboutPage/AboutPage.tsx", "isPrivate": true, "unauthenticated": "home" }, "/about-secret": { "name": "aboutSecret", "bundle": null, "matchRegexString": "^/about-secret$", "pathDefinition": "/about-secret", "hasParams": false, "routeHooks": null, "redirect": null, "relativeFilePath": "pages/AboutPage/AboutPage.tsx", "isPrivate": true, "unauthenticated": "home", "roles": "owner" }, "/about-secret-admin": { "name": "aboutSecretAdmin", "bundle": null, "matchRegexString": "^/about-secret-admin$", "pathDefinition": "/about-secret-admin", "hasParams": false, "routeHooks": null, "redirect": null, "relativeFilePath": "pages/AboutPage/AboutPage.tsx", "isPrivate": true, "unauthenticated": "home", "roles": [ "publisher", "admin" ] }, "/multi-cell": { "name": "multiCell", "bundle": null, "matchRegexString": "^/multi-cell$", "pathDefinition": "/multi-cell", "hasParams": false, "routeHooks": null, "redirect": null, "relativeFilePath": "pages/MultiCellPage/MultiCellPage.tsx", "isPrivate": false }, ```
- Loading branch information
1 parent
999bc1e
commit d80d010
Showing
16 changed files
with
263 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
- feat: feat: Reworks RSC server entries and route manifest building to derive from routes and include if route info related to authentication (#10572) by @dthyresson | ||
|
||
This PR is in furtherance of authentication support in RSC. | ||
|
||
It refactors: | ||
|
||
- How server entries are built -- not from "processing the pages dir" (which is a deprecated function) but rather the routes ... and the page info for that route. Note here that a page can be used in multiple routes, so the auth info cannot really be determined here. | ||
|
||
- The route manifest building to include per route: | ||
|
||
* isPrivate - is the route private, i.e, is it wrapped in a PrivateSet | ||
* unauthenticated - what route to navigate to if the user in not authenticated | ||
* roles - the roles to check to see if user has the require RBAC permission to navigate to the route | ||
|
||
Now if some page, route request is being handled by RSC we might be able to check if it "isPrivate" and enforce auth with the roles and even where tp redirect to if not authenticated. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.