kamaroly
How do you limit file download to authorised users only, even if they have a direct link?
I am working on app with options to upload files and share them among users, but my challenge is that a user can access the file without signing in, if they have the link or file path. I want to limit file access to only those who are logged in so that I can control who can see what file.
How can I achieve that in Phoenix? An example would be helpful.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add 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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Stefano1990
Use mix phx.gen.auth and have a look at the files it generated.
Phxie
To clarify, do you want:
If you want the second option, then its pretty straight forward as you can just make authorized routes in the router.
If you run mix.gen.auth you will get something like the below in the router.
Routes within the above scope will get automatically redirected if the user fails to pass the UserAuth requirements.
If you want the first option, to allow users to view content but not download it, I’d assume it would be more of an Nginx type thing or whatever you choose to use.
kokolegorille
You need to serve your uploaded files through a controller, not plug static. You also need to persists metadata along side your uploads, for authorization purpose, like user_id, and more if You want a more granular access.
In the controller, You will be able to check who is allowed to access your data, and use send_download.
Hermanverschooten
You can continue using
Plug.Staticby doing something similar as in this article.We have recently done this in an app, create the
staticpipeline, then combine it with a plug that does the authentication.the
:needs_indexplug just checks to see if we are asking for a path instead of a file, and tags onindex.html.The controller renders a
404, because we only get there if the file doesn’t exist.kamaroly
This is what I was looking for. I ended up having a controller that looks like this