What's the best way to use feature flags in AngularJS / Rails?

For an app with Rails Backend and AngularJS up front, how do I implement feature flags, or in other words, conditional functions for each user?

This video gave some insight on how to do it, which looks pretty rough to me.

I am using Rollout Gem for this authorization. In case feature flags are fully implemented on the client side, I believe it will be "Not so safe and reliable way to disable / enable features"

I cannot use <% if $rollout.active?(:chat, current_user) %>

in partials, since they are not ERB, but HTML pages used as angular templates.

Thanks in advance.


source to share

1 answer

So you can use JWT

. JWT is a token that you can use with your rails device to authenticate users. Imagine this is a hotel card. Depending on how much you paid, you get access to some services or others. This might allow you to get to the garage or breakfast.

Moving on to the technical details, when a user logs into your application, rails will create one of these tokens, and rails can put any flag you want there, so you can send a token containing:

{user_id: 3, rollout: true, admin: true}


So, Angular aside, you can parse this token and activate the sections you want: something like this:

<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 changed, so the end user cannot change it because the server will reject it.

In Angular you can't do too much else, any user can create an object user

and put all flags to true, but this is the rails API that decides what the user can see, so at most, use can get a blank admin page without any data, but it cannot be avoided.

If you want to know more about JWT here is the idea and here are examples (including rails)



All Articles