redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.15k stars 979 forks source link

Error replacing existing auth provider #2685

Open Tobbe opened 3 years ago

Tobbe commented 3 years ago

I tried to setup supabase auth

tobbe@XPS9550 MINGW64 ~/dev/redwood/performance-management (main)
$ yarn rw setup auth supabase
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\performance-management\node_modules\.bin\rw setup auth supabase
Existing auth provider found.
Use --force to override existing provider.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It correctly detected that I already had an auth client, and asked me to run the command again, with --force, so I did. But even with --force it fails.

tobbe@XPS9550 MINGW64 ~/dev/redwood/performance-management (main)
$ yarn rw setup auth supabase --force
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\performance-management\node_modules\.bin\rw setup auth supabase --force
C:\Users\tobbe\dev\redwood\performance-management\node_modules\@redwoodjs\cli\dist\commands\setup\auth\auth.js:123
    throw new Error('Could not replace existing auth provider init');
          ^

Error: Could not replace existing auth provider init
    at removeOldAuthProvider (C:\Users\tobbe\dev\redwood\performance-management\node_modules\@redwoodjs\cli\dist\commands\setup\auth\auth.js:123:11)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async addConfigToApp (C:\Users\tobbe\dev\redwood\performance-management\node_modules\@redwoodjs\cli\dist\commands\setup\auth\auth.js:161:15)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The project is currently using goTrue auth

I'm not on the latest version of RW, so sorry if this has already been fixed

tobbe@XPS9550 MINGW64 ~/dev/redwood/performance-management (main)
$ yarn rw info
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\performance-management\node_modules\.bin\rw info

  System:
    OS: Windows 10 10.0.19041
  Binaries:
    Node: 15.4.0 - ~\AppData\Local\Temp\yarn--1622565179883-0.7588021952890174\node.CMD
    Yarn: 1.22.4 - ~\AppData\Local\Temp\yarn--1622565179883-0.7588021952890174\yarn.CMD
  Browsers:
    Chrome: 90.0.4430.212
    Edge: Spartan (44.19041.964.0), Chromium (91.0.864.37)
  npmPackages:
    @redwoodjs/core: 0.29.0 => 0.29.0

Done in 5.36s.
peterp commented 3 years ago

I wonder if we need something like https://github.com/facebook/codemod to match "what to replace and where" instead of using regex?

Is the root cause of this issue that we're matching the incorrect thing?

Tobbe commented 3 years ago

@peterp I don't think that's the the only thing.

After I got that error message I removed everything auth related from App.js, and re-ran the command, again with --force and then it started to complain about regex mismatches.

jtoar commented 2 years ago

I tried reproducing this by setting up dbAuth then supabase. While the supabase setup command finished, it left me in a broken state. It didn't change the AuthProvider's type and client:

// Still dbAuth and no client
<AuthProvider type="dbAuth">

We could achieve this kind of precision with jscodeshift. But this issue raises the larger question of: how easy is it / how easy should we make it to switch between setup commands? (Not just for auth but for deployment, ui too)

Accordingly, https://github.com/redwoodjs/redwood/issues/3683 is one solution to this.

thedavidprice commented 2 years ago

I do not think we should support, via command line, swapping Auth providers. Instead, we can focus on documentation. (I believe someone recently documented swapping auth providers, but I couldn't find it across Forums or Discord.)

will-ks commented 2 years ago

I encountered this issue today while replacing Netlify Identity.

I was able to solve it by removing the <AuthProvider> component in App's render function. After that was removed the setup auth command completed successfully.

It didn't fully clean up the old netlify installation though, so I had to manually remove this line from App.tsx: isBrowser && netlifyIdentity.init() and also remove the netlify-identity-widget dependency from web's package.json.

Tobbe commented 2 years ago

We're currently investigating a full rewrite of how we handle different auth service providers. I think it'll be much easier to replace one for another after that. Or even run two at the same time 😮