Dynamic login between Users and the Admin #4
23nith
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
For people who need help with or may not know where to start with implementing the dynamic login feature, you may find this helpful.
Mind you, this is just one of numerous possible approaches in implementing dynamic login and is not an absolute solution. This one that I will share is the one I came up with that worked for me. Feel free to alter anything to suit your current model setup.
Steps:
I started off with adding a "role" field into my User model.
It's up to you if you want to use integer or string value type, either way just make sure to add default value to this field.. Ideally make it default to "User" and not the "Admin" role. You can just place the admin account creation within the "seed.rb" file, then run
rails db:seed.The previous step makes the role field accessible whenever you log in and access the get current_user endpoint.

Here's a screenshot of my dashboard currently in progress.
From here you can now make your logical conditions to dynamically display components or info based on the role value assigned into the "role" state.
Beta Was this translation helpful? Give feedback.
All reactions