dodo
I am working on a Phoenix Json API and would like to enable the live dashboard in production. My :require_authentication plug checks the Authorization header for a valid token, is there a way to integrate this into the live dashboard?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 10 Posts
hubertlepicki
I have something like this in my router:
Which is basically created an authenticated pipeline, that has one Plug that you seem to already have. Then, create a scope at where you want to have your dashboard, and make that scope go through the pipeline you just defined.
msimonborg
You can also drop your route into a preexisting authenticated scope if you have one
or, if you only want to require authentication in production but not in other environments:
You may want to conditionally render the link as well:
dodo
Thanks for your responses, unfortunately this does not solve my issue because I am not using
Plug.Session(cookies) for authentication. I would probably have to hook into the live dashboard JavaScript code to add the auth token into theAuthorizationheader, not sure if this is possible?hubertlepicki
I don’t see the problem, and maybe you don’t need to write a custom plug but use this Plug.BasicAuth — Plug v1.20.2 ?
dodo
Yes this would be my fallback solution but it requires admins to enter their credentials again.
hubertlepicki
Are you sure? I think if authorization header doesn’t need change, as still has valid value, it wouldn’t even prompt you to enter it again
msimonborg
I’m also a bit confused why these suggestions won’t work. You should be able to put the dashboard behind an auth pipeline, even if the auth is in the header and not the session, as long as you can put the token in the header when you send the GET request?
If none of this provides a solution to your problem, perhaps we need a little more clarity and background on what the problem is
dodo
Hi! In my SPA frontend I use
fetchand set theAuthorizationheader there for the api calls. But when navigating to/dashboard, or landing there in the first place, how would I tell the browser to set the header without modifying the LiveDashboard JavaScript? I might just switch to storing the token in a cookie because those are always automatically sent by the browser on every request.For reference, here are the relevant plugs:
msimonborg
If you have the option to use cookies that might make it simpler, especially for the case you pointed out of landing on the dashboard directly without passing through the SPA. I suppose you could have a plug for the dashboard that redirects to your SPA for authorization and then redirect from the SPA back to the dashboard.
As for navigating from SPA to dashboard, I think you can use
XMLHttpRequestto set a custom header on page navigation with JS. this Stack Overflow question may helpI’m not sure how you could hook into the dashboard JS to set the header, since you’d have to load the dashboard page to run the JS that would set your header to authorize you to view that same page. seems like a chicken and egg problem unless I’m misunderstanding
I hope any of this is helpful
chulkilee
Haven’t tested - but you may add custom endpoint to take the token from SPA and return cookie for LiveDashboard auth (e.g. with path)
LiveDashboard uses JS for socket etc. so unless it provides an extension point to add custom headers - seems like using cookie is the simplest solution.