Redwood: Generators: what happens when an auth generator is run more than once?

Created on 29 May 2020  ·  5Comments  ·  Source: redwoodjs/redwood

Right now if an auth generator is run multiple times it will add more and more lines of config to web/src/index.js which isn't the greatest experience.

  • Should the generator exit with an error if the first insert already exists? ~Or should it just skip it (with a logged note) and keep going? My first thought is to just skip the step if a quick match() says that the line that's going to be inserted is already there, but keep going to the next step.~ Yep, the first thing we should check (before the first step of adding packages) is if <AuthProvider> already exists and if so, error out with a message.
  • ~What happens if you run two different auth generators, one after the other? My first thought is to check if <AuthProvider> already exists and if the type doesn't match the generator that's about to run, exit/error and leave a note that the other auth type has already been added.~ This will be covered by the first solution.

Opinions (and PRs) welcome!

good first issue hacktoberfest kinimprovement generators

Most helpful comment

What would be the use case for running it more than once on purpose? It seems reasonable to me to just bail completely if <AuthProvider> is already set.

All 5 comments

🔥💣💥🤯

maybe?

What would be the use case for running it more than once on purpose? It seems reasonable to me to just bail completely if <AuthProvider> is already set.

We can display a warning saying that the AuthProvider already exists, or use --force flag with the generator that resets the existing AuthProvider

Here's an example of how Ruby on Rails handles this scenario

This is the warning I get when I try to create a User model that already exists

The name 'User' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --force to skip this check and run this generator again.

Running the generator again with --force will reset the existing model, i.e. It removes the code that we had earlier

@thedavidprice @peterp I'd be interested in tackling this one. Do we want to implement a --force flag that lets the user overwrite their previous AuthProvider? I think that sounds pretty useful!

@amorriscode see @mojombo's previous comment

Was this page helpful?
0 / 5 - 0 ratings