[discourse] Setup OpenFeature Web provider to fetch flags with context #4331
-
Originally posted by flg on Discourse Hello ! I’m trying to implement in my app Flipt using openFeature. In the backend, no problem with dynamic eval. On the frontend (React), because of static eval, the provider fetches all flags on: That means that any of my user would be able to see all the segments, rules etc. Is there a way to fetch the flags with the right values based on a context for static evaluation (it’s what I use to do on flagsmith) ? Or I must do dynamic evaluation ? Thank you so much ! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
To fetch flags with user-specific context in your React frontend, you'll need to use dynamic evaluation—static evaluation will always fetch all flags for the namespace, exposing segments and rules to the client. The Flipt React SDK provides hooks like const isEnabled = useFliptBoolean('flag-key', false, 'user-id', { role: 'admin' });
const variant = useFliptVariant('flag-key', 'fallback', 'user-id', { country: 'FR' }); These hooks send evaluation requests to the Flipt server with the provided context, so the returned flag values are tailored to the user or session context you specify. This approach prevents exposing all flag rules and segments to the client, as only the evaluated result is returned, not the full flag configuration. If you want to batch multiple evaluations, There isn’t a way to do context-based static evaluation on the frontend with Flipt—dynamic evaluation is the recommended and supported approach for your use case. You can see examples of these hooks and how context is passed in the Flipt React SDK tests and hook implementations. Let me know if you want a more detailed example or have questions about integrating this with OpenFeature! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Reply from erka on Discourse: Hey flg! Thank you for raising this up. Yep, you are correct. The snapshot will include all the namespace data. If this is something you don’t want the server-side evaluation is the best choice. Let’s discuss what is the best option for you. If you’re facing a tight deadline, I suggest using the OpenFeature React sdk and JS ofrep-web provider alongside Flipt as a workaround. Flipt v1.51 has full support of OFREP. We would like to hear your feedback about it too. |
Beta Was this translation helpful? Give feedback.
-
Reply from mark on Discourse: @flg just to confirm, are you concerned that users would inspect the network traffic to see the data coming from Flipt to your client side sdks? If so, i wonder if we could introduce some kind of encryption feature using a shared secret, where we encrypt the data on the server, and then decrypt it on the client in memory. this would ensure that the data is not inspectable by the end user |
Beta Was this translation helpful? Give feedback.
-
Reply from flg on Discourse: Thank you so much for your answers, by updating to 1.51.0 and changing the provider, i have the behavior i wanted ! |
Beta Was this translation helpful? Give feedback.
Reply from flg on Discourse:
Thank you so much for your answers, by updating to 1.51.0 and changing the provider, i have the behavior i wanted !