For an app with Rails Backend and AngularJS at the front, How to implement Feature Flags or in other words conditional features per user?
This Video gave some glimpse on how to do that, which looks quite crude to me.
I am using Rollout Gem for this authorization. In case, the feature flags are implemented totally on client-side, I feel that would be "Not So Secure and Robust way of Disabling/Enabling features"
I can't use <% if $rollout.active?(:chat, current_user) %> in the partials since they are not ERBs, but HTML pages used as angular templates.
Thank you in advance.
So you could use JWT. JWT is a token that you can use with your rails app to authenticate the users. Imagine it like a hotel card. Depending on how much you paid, you get access to some services or others. It could let you access the garage or the breakfast.
Going to technical details, when a user logs in in your app, rails will create one of those tokens and rails can put there any flag you want, so you can send a token containing:
{user_id: 3, rollout: true, admin: true}
So in the Angular side, you can parse that token and activate the sections you need, something along this lines:
<div ng-if="user.rollout"></div>
So based on what you get in the token, some sections of the page will appear.
The token cannot be tampered, so the end user can't modify it because the server will reject it.
In Angular itself you cannot do too much else, any user could create a user object and put all the flags to true, but it is the rails API who decides what the user can see, so the maximum that use could get is an empty admin page without any data, but that is not avoidable.
If you want to learn more about JWT, here is the idea and here examples (including a rails one)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With