gobuffalo / buffalo-auth

Buffalo auth plugin helps adding username password authentication to your app
https://gobuffalo.io
MIT License
41 stars 28 forks source link

An error during generating basic auth #54

Closed abogushov closed 4 years ago

abogushov commented 4 years ago

I try to create an empty project and connect buffalo-auth and got an error:

Error: templates/auth/new.plush.html: line 22: "user": unknown identifier

My steps:

buffalo new app --db-type mysql --skip-yarn
go get -u github.com/gobuffalo/buffalo-auth
buffalo plugins install github.com/gobuffalo/buffalo-auth
buffalo generate auth -h

What am I doing wrong?

qwrobins commented 4 years ago

I'm having the same issue as @abogushov. I've tried editing the templates in the genny dir and then reinstalling but no luck

timhanus commented 4 years ago

I had the same problem.

After poking around for awhile it seems that what is happening is that the new.plush.html is getting caught by this transformer because it has a .plush. in the filename.
https://github.com/gobuffalo/buffalo-auth/blob/master/genny/auth/auth.go#L62

Because the user is not in thectxof the above line it creates errors. It seems like it may have been introduced here? https://github.com/gobuffalo/buffalo-auth/commit/fa569cf36921ec154ad8a3b495472389ce1cefc2

As the transforms are run serially, it never makes it to here (which I believe is the intention) because of the earlier error. https://github.com/gobuffalo/buffalo-auth/blob/master/genny/auth/auth.go#L63

If I move everything in auth/templates/templates from .plush.html to .html and rebuild (make build) it seems to resolve the issue (you do have to go rename everything back to .plush.html after you generate the auth in your target project).

I'm only a couple of hours into the ecosystem so I'm not sure what the right fix is here. (Apologies in advance as well if my diagnosis is way off)

My thoughts are:
1) wrap plushgen.Transformer(ctx)) in a function that switches on whether the function runs depending on the filename.

2) figure out how to escape the plush template in new.plush.html so that plush does not try to interpolate the values.

I'm going to keep working on it and will submit a PR when I feel like I understand the intent well enough not to break something else :)

timhanus commented 4 years ago

Added PR. If I'm wrong headed about this fix I'm happy to go back and adjust with some guidance.
https://github.com/gobuffalo/buffalo-auth/pull/55

This got me moving though.

vincegio commented 4 years ago

@timhanus tried installing your pull request as a plugin but said that it still expected gobuffalo/buffalo-auth. How'd you manage to get it going?

Seems really unfortunate that this doesn't work as it is a deal breaker for me, atleast right now. Juggling between Buffalo and Qor. Ironically both of them has some sort of issue with their respective authentication part.

timhanus commented 4 years ago

Hey @vincegio,

The way I got this to work was to 1) switch to the branch I was working on for the pull request 2) run make build from this branch which should create a buffalo-auth binary 3) Manually copy that buffalo-auth binary to your $GOPATH/bin 4) Go back to your project that you are trying to run the generate for and run buffalo g auth

Step 3 was the tricky part (for me anyway) since buffalo plugins don't pull in a dependency in the same way import ( github.com/gobuffalo/buffalo-auth) would. It actually executes a prebuilt binary.

It's kind of a pain to get it working without having it merged in. You have to jump through some extra hoops.

hookover commented 4 years ago

Can this problem be solved as soon as possible? Otherwise, what's the point of its existence?

paganotoni commented 4 years ago

👋 Hey Everybody. Sorry about this issue and the time it took us to solve it. I would love to have your help trying v1.0.8 and letting me know if it works for you.

cc @hookover @timhanus @vincegio @qwrobins @abogushov

cmorbitzer commented 4 years ago

@paganotoni 1.0.8 works for me. Thanks!

paganotoni commented 4 years ago

Great! closing this one.

hookover commented 4 years ago

@paganotoni thank you very much