Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(middleware): Add support for Middleware to SSR-Streaming server #9883

Merged
merged 40 commits into from
Jan 31, 2024

Conversation

dac09
Copy link
Collaborator

@dac09 dac09 commented Jan 25, 2024

This is a first pass at introducing middleware into the streaming server, so we can do auth on the server!

Very poor quality audio whistle stop tour of how we'd be using this: https://s.tape.sh/iMAq52op?s=1.25

Includes:

  • MiddlewareResponse, MiddlewareRequest and CookieJar classes - that make dealing with the request more ergonomic
  • Adds a ServerAuthProvider, that will use the auth context set by auth middleware
  • Forwards on cookies from the browser when making a graphql request on the server (during cell SSR)
  • Restoring the auth state from the server - to save one extra API call, and to prevent React hydration errors

Outstanding:

WIP: still failing with ArdaRequest
…dleware

* 'main' of github.com:redwoodjs/redwood:
  chore(structure): switch to vitest (redwoodjs#9878)
  chore(cli): switch to vitest (redwoodjs#9863)
  feat(dbAuth): Refactor dbAuthHandler to support WebAPI Request events (redwoodjs#9835)
  fix(crwa): remove yarn-install option for yarn 1 (redwoodjs#9881)
  chore(esbuild): dedupe esbuild config (redwoodjs#9875)
  chore(esm): convert `@redwoodjs/cli-helpers` to ESM (redwoodjs#9872)
  fix(studio): Add version checks when first running Studio (redwoodjs#9876)
CookieJar clearing a cookie
WIP: Why is vitest failing?
@dac09 dac09 marked this pull request as ready for review January 26, 2024 14:51
@dac09 dac09 added this to the SSR milestone Jan 26, 2024
@dac09 dac09 added the release:feature This PR introduces a new feature label Jan 26, 2024
packages/auth/src/AuthProvider/AuthProvider.tsx Outdated Show resolved Hide resolved
packages/auth/src/AuthProvider/AuthProvider.tsx Outdated Show resolved Hide resolved
packages/auth/src/AuthProvider/ServerAuthProvider.tsx Outdated Show resolved Hide resolved
packages/vite/src/devFeServer.ts Outdated Show resolved Hide resolved
}) => {
// @NOTE: we "Sanitize" to remove encryptedSession and cookieHeader
// not totally necessary, but it's nice to not have them in the DOM
// @MARK: needs discussion!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What needs discussion? Can you and I discuss? I want to resolve this before merging

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to call this out for awareness. It's harmless right now, but its possible a contribution or new code could leak information here.

packages/vite/src/middleware/CookieJar.ts Outdated Show resolved Hide resolved
packages/vite/src/middleware/CookieJar.ts Outdated Show resolved Hide resolved
packages/vite/src/middleware/MiddlewareRequest.ts Outdated Show resolved Hide resolved
packages/vite/src/streaming/createReactStreamingHandler.ts Outdated Show resolved Hide resolved
packages/web/src/apollo/suspense.tsx Outdated Show resolved Hide resolved
dac09 and others added 4 commits January 30, 2024 12:45
Updates comments, some types

Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
More comment tings

Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
…eat/ssr-middleware

* 'feat/ssr-middleware' of github.com:dac09/redwood:
  Apply suggestions from Tobbe's review
  Apply suggestions from Tobbe's review
  Update installation.md (redwoodjs#9887)
dac09 and others added 5 commits January 30, 2024 15:14
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
…eat/ssr-middleware

* 'feat/ssr-middleware' of github.com:dac09/redwood:
  Update packages/auth/src/AuthProvider/AuthProvider.tsx
@Tobbe Tobbe enabled auto-merge (squash) January 31, 2024 03:38
@Tobbe Tobbe merged commit ff7d79c into redwoodjs:main Jan 31, 2024
38 checks passed
@dac09 dac09 deleted the feat/ssr-middleware branch January 31, 2024 06:09
@Josh-Walker-GM Josh-Walker-GM modified the milestones: SSR, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants