ashok
I have installed Pow in Phoenix for user registration. I want to differentiate the URL and layout of my logged in users. If logged in as Admin I have created its role as admin while for normal logged in user it is User.
How can I provide the different layout to Admin user and Non-Admin users even I want to land them in different URLs lets for example for admin http://www.example.com/admin/ and for a non-admin user it will be like http://www.example.com/game.
I have read the route document of Phoenix at Routing — Phoenix v1.8.8 but not sure how to ensure that if it is admin then we need to use a new scope of admin. Can you provide me a code sample of it? Any URL which will help me on how to write code. I am beginner in this language.
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










Showing Posts 1 to 6- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
hauleth
You need to use
Phoenix.Controller.put_layout/2. So assuming that you have different scopes for admin and non admin:ashok
Thanks for the reply but how can I detect at route level that logged in user is admin or non-admin based on user role either ‘admin’ or ‘non-admin-user’
LostKobrakai
You could write a plug, which calls
put_layouton the conn depending on the roles of the user stored on the conn.danschultzer
put_layoutis the right way to deal with custom templates for certain roles, but I think what you are asking for is how to redirect the user after sign in depending on the role.You can customize the callback routes to redirect admin users: Pow — Pow v1.0.13
So you can do something like:
This will redirect admin users to the admin dashboard instead of the game page. Remember to add
routes_backend: MyAppWeb.Pow.Routesto the config.ashok
Thanks it works but has one issue any non-admin user if type /admin in the browser like https:///www.example.com/admin
it redirect that non-admin user to admin dashboard how can I prevent non-admin user to access admin user pages
danschultzer
You will need to add a plug restricting access like this: How to add user roles — Pow v1.0.13