riverrun / openmaize

No longer maintained - was an Authentication library for Plug-based applications in Elixir
Other
206 stars 30 forks source link

Don't overwrite files, change them #71

Closed miskolc closed 7 years ago

miskolc commented 7 years ago

I am working at a pretty decent sized application with phoenix and I wanted to add Authentication with OpenMaize. I was surprised when I noticed it was asking me if it should overwrite web/router.ex and other files I've been already working on.

I believe OpenMaize should work just like Devise works for Rails, you can install it whenever you want and if you've been working on certain files already, it should simply add just the lines of code you need without damaging initial file.

riverrun commented 7 years ago

Thanks for raising the issue. At the moment, I want to keep it as it is, and I'll outline why below.

  1. The generators are really designed to be used when starting an app, and several assumptions are made based on the fact that it is a new app. Designing them so that it is easier to install them at any time would add a layer of complexity that I do not see the need for. I also do not really have the time to spend doing this.
  2. There is an example app here, which developers can use to help them create the necessary files by hand.

In your case, it might just be a matter of generating the files using the mix openmaize.gen.phoenixauth, not overwriting the web/router.ex file and then editing web/router.ex by hand.

I'm closing this issue for now, but if you have any further comments, please let me know.

miskolc commented 7 years ago

The generators are really designed to be used when starting an app

So far OpenMaize has really no major competitor in becoming the Devise equivalent of Phoenix applications. However, not upgrading the generators in order to make them fit a scenario where you would add them to an existing app seems to me a bad idea that will render OpenMaize, at most, a package used for school/college homework projects, certainly not for real world apps and not even for hackathons. Even at hackathons it's generally recommended to build the app's main functionality first before adding authentications and not the other way around. I think your decisions will only limit the scope of the package usage on the long run. I don't want to be rude but these are my opinions on the decision.

guidotripaldi commented 7 years ago

Maybe it might be implemented a simple switch to the generator, for example --write-addenda that generates a file with just the addenda that we have to manually add to the already existent file(s). For example mix openmaize.gen.phoenixauth --write-addenda would produce a file addenda.router.ex (instead of the standard router.ex) with this kind of hints inside:

# put the following line(s) in your `pipeline :browser do` block of your `router.ex` file:
  plug Openmaize.Authenticate

# put the following line(s) in your ` scope "/", MyApp do` block after the `pipe_through :` line  of your `router.ex` file:
    get "/", PageController, :index
    resources "/users", UserController
    resources "/sessions", SessionController, only: [:new, :create, :delete]
    get "/sessions/confirm_email", SessionController, :confirm_email
    resources "/password_resets", PasswordResetController, only: [:new, :create, :edit, :update]
riverrun commented 7 years ago

Yes, that might be a simpler solution. I'll look into it further and get back to you.

riverrun commented 7 years ago

I'm happy to work on @guidotripaldi's solution -- creating an addenda.router.ex file that can then be copied into the web/router.ex file.

The only question then is what to do with the user* files if they already exist in a project. Should we overwrite them?

@miskolc, what do you think?

riverrun commented 7 years ago

I'm closing this in favor of improving the documentation in the wiki.