iaguirre88

iaguirre88

Support phx.gen.auth in backend applications

Hi, everyone!

Sometimes, you might want to build your app using Phoenix just for the backend and use another tool for the frontend (such as React or Vue). In this case, you would start your project with the --no-html flag.

Now, if you try using the auth generator, you’ll have this error:

However, if you’ve built your application with HTML templates, you can actually implement API authentication by following this guide: API Authentication — Phoenix v1.7.14

So I wonder whether it makes sense to adapt the auth generator to support backend-only applications.

I’ve been working on a prototype here, to validate the idea, where I’ve managed to make the registration endpoint work.

What are your thoughts on this? Does it make sense to continue working on this?

Thanks!

Most Liked

dfalling

dfalling

It would be a nice addition. When I moved over from my previous auth system, I had to add additional functions to the phx.gen.auth generated code for my API. There’s not that much to them, mainly changing flash and redirects into result types for the endpoints to return.

arcanemachine

arcanemachine

Oh nice, I’m glad they added this section. I implemented API authentication in pretty much the same manner by myself but it’s good that there’s an official guide, because there’s a good chance I screwed something up along the way. :laughing:

Thanks to the Phoenix team for taking a step away from making us roll our own authentication!

@iaguirre88 Huge fan of your proposal BTW.

(@dfalling Sorry for replying to your post, the forum UI drives me nuts. I don’t know how to un-reply to your post and I can’t delete posts on this forum.)

iaguirre88

iaguirre88

Quick update: I’m still working on this because it’s a great opportunity for me to learn and I’m having fun.
Now it supports login, logout and confirmation besides registration.

So this is the progress so far

  • Done
    • /register
    • /log_in
    • /log_out
    • /confirm
    • /confirm/:token
  • To do
    • /reset_password
    • /reset_password/:token
    • /settings
    • /settings/confirm_email/:token

Where Next?

Popular in Proposals: Ideas Top

DaAnalyst
@chrismccord @josevalim @steffend Been using colocated JS for a while and I keep on stumbling on the same limitation: there is no way (a...
New
MUSTDOS
Hello all! assign(socket, :name, “Elixir”) Why can’t we have assign/stream take a group of atoms and maps/structs as a default to r...
New
mortenlund
Hi! I would like to suggest a new callback in the lifecycle of the Live Component which is unmount. Sometimes it is nice to be able to ...
New
aglassman
Problem The cancel_async function is easily overlooked. Since the results of “outdated” tasks are ignored, it’s easy for developers to a...
New
bartblast
This could resolve to {[a: 1, b: 2]}. Was it ever considered to allow such syntax? Notice this: {:abc, a: 1, b: 2} and this: my_fun(:abc,...
New
pierrelegall
Problem Currently, List.first/2 and List.last/2 return a default value (or nil) when the list is empty. However, there are cases where an...
New
dkuku
This is a proposal to make the map key mismatch errors a bit better: Every time I have a typo It’s very challenging for me even when I u...
New
Astolfo
When generating a release with phx.gen.release --docker a debian version is used by default to avoid “DNS issues” on Alpine. It seems li...
New
mxgrn
As one edits a Phoenix LiveView form in a modal, it’s very easy to accidentally press ‘Esc’ and lose all the edits. Similar to data-conf...
New
dibok
Hi, I’m trying to use phoenix.js in my Qt QML project which has it’s own buildin JavaScript engine. Problem is that (what I googled so f...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement