TrueCar / react-launch-darkly

Simple component helpers to support LaunchDarkly in your React app.
MIT License
76 stars 20 forks source link

Is there a way to get all feature flags for a user ? #58

Closed balpal4495 closed 6 years ago

balpal4495 commented 6 years ago

i know that there is a function called getAllFeatureFlags in the utils file, but this doesn't seem to be working correctly.

jacobmoretti commented 6 years ago

Hi @balpal4495, sorry for the late response. Can you show me your current usage of getAllFeatureFlags? We currently use that function at TrueCar and it works as expected for us.

Just to add, getAllFeatureFlags does require the args key, user, key being your LaunchDarkly client ID and user being the LaunchDarkly user object as defined here: https://docs.launchdarkly.com/docs/js-sdk-reference#section-users

balpal4495 commented 6 years ago

@jacobmoretti Thanks for your response, I was trying to use getAllFeatureFlags by wrapping it in a an async/await function within my react component. and passed the user and key to it in the parameters, but i simply kept getting back an empty object.

jacobmoretti commented 6 years ago

Your use case shouldn't be a problem. Do you mind sharing the code of your implementation? We use getAllFeatureFlags successfully in the exact same way with async/await. Curious why this is failing for you.

balpal4495 commented 6 years ago

so i would be using it in this way.

import { getAllFeatureFlags } from 'react-launch-darkly';

export const getFlags = async (user) => {
  cost response = await getAllFeatureFlags(user)
  return response;
}

This just returns back an empty object

jacobmoretti commented 6 years ago

getAllFeatureFlags takes two args: https://github.com/TrueCar/react-launch-darkly/blob/master/src/lib/utils.js#L82

The first argument needs to be your LaunchDarkly client id. Second argument is the user object.

balpal4495 commented 6 years ago

So i tried that and it didn't seem to make any difference.

import { getAllFeatureFlags } from 'react-launch-darkly';

export const getFlags = async (clientId, user) => {
  cost response = await getAllFeatureFlags(clientId, user)
  return response;
}

I receive a promise, and if i check the the response from .then I simple receive an empty object.

I checked the docs on launchdarkly , and they specify that a user is sent as a parameter to get allFlags.

so should the user not be added to the params on this line https://github.com/TrueCar/react-launch-darkly/blob/b99c6fd894bf593b186b8c799240dda5aee95d34/src/lib/utils.js#L86 ?

balpal4495 commented 6 years ago

ok, never mind that, i figured it out.

i was using using a user id for the key and it should have been like this.

solution if anybody is stuck on the same issue.

getAllFeatureFlags(clientId, { key: user } )
jacobmoretti commented 6 years ago

Ahh yes that would be a problem. Those two args are described here: https://github.com/TrueCar/react-launch-darkly#props. At the moment getAllFeatureFlags is undocumented, mostly because I've been trying to come up with a solution for it where you don't have to pass the client id and user object.

jacobmoretti commented 6 years ago

Closing this issue as its been resolved.