zizheng
Using Pow for simple API authentication?
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!)
Marked As Solved
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.
Also Liked
danschultzer
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.
Last Post!
danschultzer
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









