martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
407 stars 23 forks source link

Add the ability to generate the auth application in existing projects #102

Closed ellmetha closed 10 months ago

ellmetha commented 1 year ago

Description

The new management command allows to generate new projects or new application structures. When generating new project structures, a --with-auth option can also be leveraged in order to add an auth application to the generated project, which adds support for basic authentication.

It would be interesting to be able to easily generate a new auth application structure to make it easier adding authentication to existing projects. In this light, let's ensure that it is possible to call the new management command as follows:

marten new auth

This new structure type should support the interactive mode that was introduced in #74. It should also support the use of other existing command options and arguments. For example:

marten new auth myauth --dir=./apps/auth
kates commented 12 months ago

I have a PoC but I haven't yet figured out how to add Auth::App in the settings installed_apps. Any idea how to go about it?

kates commented 12 months ago

I think I found my solution here https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/syntax/transformer.cr.

ellmetha commented 12 months ago

Hey @kates! Thanks for taking a look into this.

Since I wrote the issue I actually changed the initial plan around the addition of this capability (and I forgot to close this issue 🤦). The goal now is to add that through the new generator mechanism that is being implemented as part of #121. With the upcoming 0.4 release, the new management command will be used only for generating new repositories (projects or third-party apps) while the gen management command will be used to generate various files and structures within an existing project.

As such, generating the auth application should probably be implemented as a generator moving forward. For example:

marten gen authapp

The core of the generator implementation is already there and we can probably add a new generator (under src/marten/cli/generator) in order to take care of the generation of the auth app within an existing project.

ellmetha commented 10 months ago

The auth generator was added as part of #121, which means that it will be possible to generate an authentication application within an existing project starting with the 0.4 release. 🚀 Closing this issue.