zizheng
I’m creating a Phoenix API backend that will be used with a Vue frontend app. I have experience building a traditional server-rendered app that uses Pow for authentication, but have never built a SPA before.
I’ve gone through How to use Pow in an API — Pow v1.0.39, which makes me question if Pow is the right choice for my case. Our app is an internal management system used by at most a dozen users, so stateless token authentication shouldn’t be a requirement (i.e. we can afford to check the DB on every request), and introducing the refresh token & access token distinction seems to introduce a lot of unnecessary complexity.
Would it be reasonable in my case to hand-roll something like this?
- Authenticate against a
userstable - Store sever-side sessions in a
sessionstable in say Postgres, with roughly the following schema:id, user_id, inserted_at, updated_at. Theupdated_atcolumn can be used to implement a TTL, say 2 weeks, and can be updated every time an authenticated user sends a request. - The token sent to the frontend app is simply a signed session ID.
- (I’m not sure what to do if I want to access additional information, say user permissions, in the frontend app though. In a server-rendered Pow app, I would just consult a
permissionsfield on thecurrent_userassign set by Pow. Any suggestion is appreciated!)
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lud
You don’t have to do that at all if the only consumer for your API is the Vue app ; you can just use the default authentication mechanism from Pow. All you have to do is to ensure that the
credentials(i.e. cookies) are enabled in Vue resource (if you use this library).To access informations such as permissions I would simply add an API route to fetch the info.
hauleth
You do not need Pow for that. I would just use
Plug.Sessionwith properPlug.Session.Store.zizheng
Is there anything wrong if I do what @lud suggested and just use the normal session-based approach with Pow?
hauleth
You do not need Pow in that case.
Plug.Sessionis built in feature intoplug, so you have that already.zizheng
I’m not sure I follow. That’s just the session part though, I’ll still need to actually do the authentication somehow, either with Pow or hand-roll my own solution.
hauleth
Create your custom store (untested, written from memory):
And then in your controller:
put_session(conn, :user_id, uid)get_session(conn, :user_id)delete_session(conn, :user_id)lud
If Pow id used for registration, password recovery and all other features, there is no need to implement your own session solution.
hauleth
If - this is important part, if it is not used, then you can implement most of it’s features quite quickly without all that fuss.
danschultzer
Yeah, @lud’s recommendation is the best approach. You won’t have to do any additional work and you’ll have session renewal out of the box.
The API guide, though being a simple generic way of setting up API auth, is more useful for mobile apps, and third party integration.