Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into feat/return-…
Browse files Browse the repository at this point in the history
…tuples-dbauth-mw

* 'main' of github.com:redwoodjs/redwood:
  fix(deps): update dependency isbot to v5 (redwoodjs#10340)
  chore(deps): update dependency vscode-languageserver-protocol to v3.17.5 (redwoodjs#10351)
  chore(deps): update node.js to >=14.17 <=20.13 (redwoodjs#10368)
  fix(deps): update dependency graphql-sse to v2.5.3 (redwoodjs#10364)
  chore(deps): update dependency @supabase/supabase-js to v2.43.2 (redwoodjs#10365)
  chore(deps): update babel monorepo to v7.24.5 (redwoodjs#10614)
  fix(vite): Rename `serverAuthContext` to `serverAuthState` (redwoodjs#10653)
  feat(middleware): Add .shortCircuit to MiddlewareResponse (redwoodjs#10586)
  chore(ssr): Make entry.client.tsx better match standard entry.client (redwoodjs#10652)
  patch(crwa): Fix small annoyances (formatting, spell-check) (redwoodjs#10651)
  chore(ci): Update rsc readme (redwoodjs#10650)
  chore(serverAuth): Rename serverAuthContext to serverAuthState where relevant (redwoodjs#10643)
  chore(deps): Remove unused deps from prerender (redwoodjs#10649)
  Add missing rwjs/auth deps (redwoodjs#10648)
  feat(rsc-auth): Implement serverStore to hold and pass req info to RSC (redwoodjs#10585)
  chore(deps): Remove unused octokit package (redwoodjs#10645)
  chore(deps): bump @fastify/reply-from from 9.4.0 to 9.8.0 (redwoodjs#10644)
  • Loading branch information
dac09 committed May 21, 2024
2 parents 6c3010f + 76151f1 commit 01206ef
Show file tree
Hide file tree
Showing 83 changed files with 1,060 additions and 933 deletions.
4 changes: 2 additions & 2 deletions .changesets/10499.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Implement Supabase Auth Middleware to authenticate server-side requests.
* createSupabaseAuthMiddleware is responsible for authenticating Supabase requests
* It does so by checking if the request has a supabase auth-provider header, and then uses the authDecoder to verify the session cookie using the Supabase ServerAuthClient and returning a decoded access token -- or throwing an exception if the session cookie is invalid
* Once the middleware has the decoded JWT, it hands that to the provided getCurrentUser from he user's project to return the information about authenticated user
* Lastly, it sets serverAuthContext with user and metadata info to know the request isAuthenticated
* If the session is invalid or the cookie tampered with such that the access token cannot be verified, serverAuthContext is cleared as are the auth provider and Supabase cookies
* Lastly, it sets serverAuthState with user and metadata info to know the request isAuthenticated
* If the session is invalid or the cookie tampered with such that the access token cannot be verified, serverAuthState is cleared as are the auth provider and Supabase cookies


15 changes: 15 additions & 0 deletions .changesets/10585.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- feat(rsc-auth): Implement serverStore to hold and pass req info to RSC (#10585) by @dac09

First pass at implementing a per-request store that allows:

- access to headers and cookies from requests in server components
- access to serverAuthState from server components
- maps serverAuthState updated from middleware to the the per request store

This PR also implements execution of middleware in the RSC handler. Note that this is done in a "good enough" way currently, because the RSC handler doesn't use Fetch requests (but everything else does)

Important things to note:
- the store is initialised _again_ in the RSC worker, with the same values on each invocation of renderRsc
- we have _not_ tested or tried in Dev because `rw dev` does not work in RSC yet
- we have _not_ tested behaviour on initial SSR - because this is not implemented yet in RSC

30 changes: 30 additions & 0 deletions .changesets/10586.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- feat(middleware): Add .shortCircuit to MiddlewareResponse (#10586) by @dac09

Adds a helper to generate a intercept/short-circuit response, that will interrupt execution of _all_ middleware and react rendering, and immediately return the response.

There's a few different ways you can use this, see examples below:

```ts
const shortCircuitMw: Middleware = (req, res) => {
// A) You can short circuit after building the response (or use the res param)
// This allows you to use all the convenience helpers like cookies of MW Response
if (req.url.includes('create-new-response')) {
const shortCircuitResponse = new MiddlewareResponse('Short-circuiting')
shortCircuitResponse.headers.set('shortCircuit', 'yes')
shortCircuitResponse.cookies.set('shortCircuitCookie', 'do-not-allow', {
expires: new Date(Date.now() + 1000 * 60 * 60),
})
shortCircuitResponse.shortCircuit()
}

// B) You can directly construct a new short-circuit response
// (discarding whatever response was built before)
if (req.url.includes('using-existing-res')) {
res.shortCircuit('Short-circuiting directly', {
headers: { shortCircuitDirect: 'yes' },
})
}

}
```

9 changes: 9 additions & 0 deletions .changesets/10643.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- chore(serverAuth): Rename serverAuthContext to serverAuthState where relevant (#10643) by @dac09

**Why?**
As we make auth available on RSC, we want to avoid the use of the word "context"

1. Because context is over used
2. It's confusing because RSCs don't support React.context

This PR renames `serverAuthContext` -> `serverAuthState`. The only case it doesn't change it is the _actual_ ServerAuthContext which is a React context we use for SSR/Streaming
14 changes: 14 additions & 0 deletions .changesets/10651.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- patch(crwa): Fix small annoyances (formatting, spell-check) (#10651) by @Tobbe

cSpell was complaining about "prerendering". I added it to the dictionary in
project workspace settings. This gets rid of the blue squiggles for the RW
project, but not for any user project. I could also have changed it to
"pre-rendering", but we call the feature "prerender", so it didn't feel right
to change it to "pre-rendering". So this will have to do for now.

Also formatted the source code to me more narrow.

Honestly this is more of a chore than a fix. But it does affect user projects
(at least new user projects). So I marked it "patch". But no change needed for
existing projects unless they really want (and haven't already done it
themselves).
6 changes: 3 additions & 3 deletions .github/actions/set-up-rsc-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This action creates a RW project with Streaming SSR and RSC support set up.
It's used for RSC smoke tests.

It runs `npx -y create-redwood-app@canary ...` to set the project up with the
latest canary release of Redwood. It then runs
It runs `yarn create redwood-app -y ...` to set the project, and then upgrades
it to the latest canary release of Redwood. After that it runs
`experimental setup-streaming-ssr` and `experimental setup-rsc` followed by
a build of the rw app. Finally it runs `project:copy` to get the latest
changes to the framework (i.e. the changes introduced by the PR triggering this
Expand All @@ -27,6 +27,6 @@ the action on your own machine and by `setupRscProjectGitHib.mjs` when it's
triggered by GitHub CI.

When doing further changes to the code here it's very important to keep the
DI scripts as light on logic as possible. Ideally all logic is kept to
CI scripts as light on logic as possible. Ideally all logic is kept to
`setUpRscProject.mjs` so that the same logic is used both locally and on
GitHub.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"opentelemetry",
"pino",
"Pistorius",
"prerendering",
"redwoodjs",
"rsdw",
"RWJS",
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/test-project/web/src/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const redwoodAppElement = document.getElementById('redwood-app')

if (!redwoodAppElement) {
throw new Error(
"Could not find an element with ID 'redwood-app'. Please ensure it exists in your 'web/src/index.html' file."
"Could not find an element with ID 'redwood-app'. Please ensure it " +
"exists in your 'web/src/index.html' file."
)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/.node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.11.1
20.13.1
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"resolutions": {
"vscode-languageserver": "6.1.1",
"vscode-languageserver-protocol": "3.15.3",
"vscode-languageserver-protocol": "3.17.5",
"vscode-languageserver-textdocument": "1.0.11",
"vscode-languageserver-types": "3.17.5",
"@storybook/react-dom-shim@npm:7.6.17": "https://verdaccio.tobbe.dev/@storybook/react-dom-shim/-/react-dom-shim-8.0.8.tgz"
Expand All @@ -49,9 +49,9 @@
"@actions/core": "1.10.1",
"@actions/exec": "1.1.1",
"@actions/glob": "0.4.0",
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@babel/generator": "7.24.1",
"@babel/generator": "7.24.5",
"@babel/node": "7.23.9",
"@babel/plugin-proposal-decorators": "7.24.1",
"@babel/plugin-transform-class-properties": "^7.22.5",
Expand All @@ -63,7 +63,7 @@
"@babel/preset-env": "^7.22.20",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.22.15",
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@faker-js/faker": "8.4.1",
"@npmcli/arborist": "7.5.2",
"@playwright/test": "1.44.0",
Expand Down Expand Up @@ -102,7 +102,6 @@
"nodemon": "3.1.0",
"npm-packlist": "8.0.2",
"nx": "19.0.4",
"octokit": "3.2.1",
"ora": "7.0.1",
"prompts": "2.4.2",
"rimraf": "5.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@prisma/client": "5.14.0",
"@whatwg-node/fetch": "0.9.17",
"core-js": "3.37.1",
Expand All @@ -43,7 +43,7 @@
"title-case": "3.0.3"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/aws-lambda": "8.10.138",
"@types/jsonwebtoken": "9.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/auth0/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"core-js": "3.37.1",
"jsonwebtoken": "9.0.2",
"jwks-rsa": "3.1.0"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@redwoodjs/api": "workspace:*",
"@types/jsonwebtoken": "9.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/auth0/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/cli-helpers": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"typescript": "5.4.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/auth0/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/auth": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@auth0/auth0-spa-js": "2.1.3",
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/react": "^18.2.55",
"react": "19.0.0-beta-04b058868c-20240508",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/azureActiveDirectory/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"core-js": "3.37.1",
"jsonwebtoken": "9.0.2",
"jwks-rsa": "3.1.0"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@redwoodjs/api": "workspace:*",
"@types/aws-lambda": "8.10.138",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/cli-helpers": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"typescript": "5.4.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/azureActiveDirectory/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/auth": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@azure/msal-browser": "2.38.4",
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/netlify-identity-widget": "1.9.6",
"@types/react": "^18.2.55",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/clerk/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@clerk/clerk-sdk-node": "4.13.16",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@redwoodjs/api": "workspace:*",
"@types/aws-lambda": "8.10.138",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/clerk/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"prepublishOnly": "NODE_ENV=production yarn build"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/cli-helpers": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"typescript": "5.4.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/clerk/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/auth": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@clerk/clerk-react": "4.31.1",
"@clerk/types": "3.64.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/custom/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/cli-helpers": "workspace:*",
"core-js": "3.37.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"typescript": "5.4.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/dbAuth/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.1",
"@babel/runtime-corejs3": "7.24.5",
"@redwoodjs/project-config": "workspace:*",
"base64url": "3.0.1",
"core-js": "3.37.1",
"md5": "2.3.0",
"uuid": "9.0.1"
},
"devDependencies": {
"@babel/cli": "7.24.1",
"@babel/cli": "7.24.5",
"@babel/core": "^7.22.20",
"@redwoodjs/api": "workspace:*",
"@simplewebauthn/server": "7.4.0",
Expand Down
Loading

0 comments on commit 01206ef

Please sign in to comment.