roostercrab

roostercrab

How to use phx.gen.auth

Hi, I’m trying to figure out how to use the new phx.gen.auth generator and I have followed through with the commands here:

But I don’t see what I am supposed to do after that. I can create accounts and be logged in, but how do I set pages so that they are behind the authentication wall?

I’ve even looked at Jose’s demo app here:

but I can’t see how it isn’t just a regular Phoenix app named demo?

Marked As Solved

josevalim

josevalim

Creator of Elixir

Look at the router:

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I believe this pull request is relevant too: https://github.com/dashbitco/mix_phx_gen_auth_demo/pull/1

thojanssens1

thojanssens1

As Jose said, you can find the plug :require_authenticated_user being used in the router file, protecting routes against unauthenticated users. You can find the code of that plug in the controllers, in the (your schema name)Auth module.

What I personally did to see clearly all the code being generated, is creating two new Phoenix projects. On one of them I run the generator. Then I compare the code of both projects with my diff tool, study, and copy code into my project.

Last Post!

roostercrab

roostercrab

For anybody else having the same trouble, the auth branch in the demo is the one with the code that shows you how it works.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New

We're in Beta

About us Mission Statement