-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Decouple auth #5985
Decouple auth #5985
Conversation
✅ Deploy Preview for redwoodjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
87afc35
to
966916d
Compare
@Tobbe One of the things that I would like to have for tRPC is the ability to implement my over version of redwood/packages/auth/src/AuthProvider.tsx Lines 194 to 223 in 2cb1226
|
966916d
to
c175b8e
Compare
e1a4ffd
to
2366047
Compare
…e-decouple-auth-web Conflicts: packages/api/src/index.ts packages/auth-providers-api/package.json packages/auth-providers-setup/package.json packages/auth-providers-setup/src/custom/templates/web/auth.ts.template packages/auth-providers-setup/src/dbAuth/templates/api/functions/auth.ts.template packages/auth-providers-setup/src/dbAuth/templates/api/functions/auth.webAuthn.ts.template packages/auth-providers-web/package.json packages/auth2/package.json packages/cli-helpers/README.md packages/cli-helpers/package.json packages/cli-helpers/src/auth/__tests__/fixtures/dbAuthSetup/templates/api/functions/auth.webAuthn.ts.template packages/cli/package.json packages/cli/src/commands/generate/sdl/sdl.js packages/cli/src/commands/setup/auth/__tests__/authHandler.test.js packages/cli/src/commands/setup/auth/auth.js packages/graphql-server/package.json packages/graphql-server/src/functions/useRequireAuth.ts packages/graphql-server/src/plugins/__tests__/useRedwoodAuthContext.test.ts packages/router/package.json packages/router/src/__tests__/router.test.tsx packages/router/src/router-context.tsx packages/telemetry/src/sendTelemetry.ts packages/web/package.json packages/web/src/apollo/index.tsx yarn.lock
I think this broke Auth with Supabase... Edit: Hmm is the thought here that Redwood won't provide any providers OOTB anymore? |
…aching * 'main' of github.com:redwoodjs/redwood: (244 commits) chore(deps): update dependency @replayio/playwright to v0.3.0 (#6735) chore: update all contributors Update Clerk docs (#6712) Update firebase auth docs (#6717) Clerk: Simplify web implementation (#6713) Add auth decoder to clerk auth setup (#6718) Auth: Update firebase setup script (#6716) chore: Remove redundant space " " (#6714) Update the Clerk setup script and templates (#6710) Fix decouple auth related type errors (#6709) fix(deps): update dependency css-minimizer-webpack-plugin to v4.2.2 (#6688) fix(deps): update dependency @graphql-codegen/cli to v2.13.7 (#6687) feat: publish 2nd canary (@next) from release branch (#6505) fix: don't pr if can't cherry pick cleanly (#6703) fix(dbAuth): add required packages to setup command (#6698) Netlify: Enable auth-providers-api and auth-providers-web installation (#6697) chore: make misc change to trigger canary publishing (#6695) chore: remove private on new packages (#6692) chore: run lint fix (#6691) Decouple auth (#5985) ...
Kind of. The end goal is to provide them all as plugins. Redwood doesn't have plugins yet though, so until it does, they'll still be part of Redwood like they are now, just in a different package. |
An attempt at some release notes:
For this release Redwood has totally revamped its authentication subsystem. The biggest change is that all auth providers are totally decoupled from Redwood's internals. We're doing this for a couple of reasons. One reason is we want to make maintaining the auth providers more sustainable for Redwood as a project. Auth providers can now be their own packages on NPM, so we're hoping devoted community members and auth companies will take over maintenance and ownership of auth providers, so we can focus on adding other features to Redwood. Another big reason is we wanted to make it easier for anyone to write their own custom auth provider. And finally we wanted to make it possible to have multiple auth providers configured at the same time. This is great if you for example want to switch from one provider to another and need to run both for a short time while moving all your users over to the new provider. Or if you want to have a different auth system for API access to your app.
To pull this off we had to make some majorly breaking changes. To make auth less tied to RW internals we've a little bit more code into user apps. You'll see this in a new
auth.{js,tsx?}
file in/web/src
. For most project it should be enough to run our auth setup command again, passing in your current auth provider and the--force
flag. But please make sure you commit all your currently modified files to git before running the setup command so you easily can review what changes it does to your files before committing them.I started out just wanting to provide better types for the auth client methods, like
logIn
in the snippet belowWhen I started working on my solution I soon realized that this new implementation would also allow us to fully decouple the vendor specific auth logic. Plus finally allow users to truly implement their own custom auth solutions and integrations.
Looking at
redwood/packages/auth/src/authClients/SupportedAuthClients.ts
Lines 34 to 41 in 821e594
we can see that we already had a bit of a factory pattern going. I took that idea and ran with it 🙂
So now everything starts with using a factory to create the
<AuthProvier>
component anduseAuth
hook that we need for RW's auth.The key is we can use a vendor-specific "create" method that injects the types from that vendor into the generic auth methods provided by us, the RW framework.
I haven't started updating our auth generator yet, but what's going to be different is I'm going to make it generate a new
auth.{js,ts}
file next toApp.{js,tsx}
. It will look something like thisAnd with that file
App.tsx
would look something like thisSo
App.tsx
would look the same no matter what auth provider you use. Onlyauth.ts
would changeHere's a slightly trimmed down version of the Netlify factory
To implement this in user-land as a custom auth provider all that would have to change is to import
createAuthentication
andAuthImplementation
from@redwoodjs/auth
instead. And then inauth.ts
importcreateNetlifyAuth
from wherever the user placed it instead of importing it from the RW framework.Testing
Breaking changes and codemods
useAuth
is no longer exported from@redwoodjs/auth
NoverifyOTP
for supabase anymore. Have to use it fromclient
insteadDon't think there actually was any way to access this method anyway. So not breaking to remove
But do double-check this
getUserMetadata
no longer injectsroles
on the root object. Only returns the Clerk user objectShould we replace all
@redwoodjs/auth
imports withsrc/auth
?Should we try to detect what auth prover a project is using and then run the
rw setup auth
command for that auth service provider? Or should we just tell the user to do that on their own?Need to clean up from old auth in App.js,tsx
Decision log
2022-08-16. On today's core-team meeting we decided to keep the
client
name that you get by destructuring the return value fromuseAuth()
Left to do
See if we can give access to the "raw" auth provider client lib/sdk. Perhaps by augmentingAnother option is to pass it touseAuth
insideauth.ts
in user-land, unless I can come up with something better.createAuthentication -> createAuthProvider
and store it in AuthContext like we already do. Just have to make sure we can pass the types along.client
name, or should we perhaps go with something likeproviderClient
? Keepingclient
.global.__REDWOOD__USE_AUTH
packages/auth/README.md
useAuth
. Test both logged in and logged out statedecoded
type supported for parseJWTupdateApiImports
codemod. Do we need a new one now? (Touches on DbAuthHandler)Things moved away from the list above for handling in future PRs
any
types in DbAuthoptions
types. Currently they're allunknown
inAuthContext.ts
, e.g.logIn(options?: unknown): Promise<TLogIn>
. Might have to do aTLogInOptions
generic for itroles[]
(vs role | roles[]) for auth providers (not for users)auth.ts
for TS projects andauth.js
for JS projects as part ofnotes
in setup scriptfirebaseAuth2.ts
if multiple auth providers have been set up.Closes #3617 #1585