diff --git a/src/app/system/flags/Components/WrappedFlagProvider.tsx b/src/app/system/flags/Components/WrappedFlagProvider.tsx index 39e7247a25e..836e9b01b8d 100644 --- a/src/app/system/flags/Components/WrappedFlagProvider.tsx +++ b/src/app/system/flags/Components/WrappedFlagProvider.tsx @@ -3,6 +3,8 @@ import FlagProvider, { IConfig, useFlagsStatus } from "@unleash/proxy-client-rea import { useUnleashEnvironment } from "app/system/flags/hooks/useUnleashEnvironment" import { useUnleashInitializer } from "app/system/flags/hooks/useUnleashInitializer" import { useUnleashListener } from "app/system/flags/hooks/useUnleashListener" +import { Platform } from "react-native" +import DeviceInfo from "react-native-device-info" import Keys from "react-native-keys" export const WrappedFlagProvider: React.FC = ({ children }) => { @@ -11,6 +13,12 @@ export const WrappedFlagProvider: React.FC = ({ children }) => { const storageName = (name: string) => `unleash-values:${name}` const config: IConfig = { + context: { + properties: { + appVersion: DeviceInfo.getVersion(), + appPlatformOS: Platform.OS, + }, + }, url: env === "production" ? Keys.secureFor("UNLEASH_PROXY_URL_PRODUCTION") diff --git a/src/app/system/flags/hooks/useUnleashInitializer.ts b/src/app/system/flags/hooks/useUnleashInitializer.ts index 68e7bc74fa2..e9ae550e828 100644 --- a/src/app/system/flags/hooks/useUnleashInitializer.ts +++ b/src/app/system/flags/hooks/useUnleashInitializer.ts @@ -1,15 +1,24 @@ import { useUnleashClient } from "@unleash/proxy-client-react" import { GlobalStore } from "app/store/GlobalStore" +import { jwtDecode } from "jwt-decode" import { useEffect } from "react" export const useUnleashInitializer = () => { const client = useUnleashClient() const userID = GlobalStore.useAppState((state) => state.auth.userID) + const userAccessToken = GlobalStore.useAppState((state) => state.auth.userAccessToken) useEffect(() => { if (userID) { if (client.getContext().userId !== userID) { client.setContextField("userId", userID) + + if (userAccessToken) { + const decodedToken = jwtDecode(userAccessToken) as { roles: string } + + const userRoles = decodedToken["roles"] ?? "" + client.setContextField("userRoles", userRoles) + } } client.start() @@ -20,5 +29,5 @@ export const useUnleashInitializer = () => { return () => { client.stop() } - }, [userID]) + }, [userID, userAccessToken]) }