Skip to content

Commit

Permalink
fix: fetch unleash toggles/variants after user has logged in (#11339)
Browse files Browse the repository at this point in the history
* fix: fetch unleash toggles/variants after user has logged in

* fix: start unleash client each time user logs in
  • Loading branch information
gkartalis authored Jan 6, 2025
1 parent 16bbd91 commit 4529b08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/store/AuthModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActionType, AuthService, CreatedAccount, ResetYourPassword } from "@artsy/cohesion"
import Braze from "@braze/react-native-sdk"
import { appleAuth } from "@invertase/react-native-apple-authentication"
import AsyncStorage from "@react-native-async-storage/async-storage"
import CookieManager from "@react-native-cookies/cookies"
import { GoogleSignin, statusCodes } from "@react-native-google-signin/google-signin"
import * as Sentry from "@sentry/react-native"
Expand Down Expand Up @@ -1012,6 +1013,7 @@ export const getAuthModel = (): AuthModel => ({
__DEV__ && (await clearNavState()),
await signOutGoogle(),
LoginManager.logOut(),
await AsyncStorage.clear(),
CookieManager.clearAll(),
_globalCacheRef?.clear(),
])
Expand Down
7 changes: 5 additions & 2 deletions src/app/utils/experiments/UnleashProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export function UnleashProvider({ children }: { children?: React.ReactNode }) {
const { unleashEnv } = useUnleashEnvironment()

useEffect(() => {
if (isHydrated) {
if (isHydrated && userId) {
const client = getUnleashClient({ env: unleashEnv, userId })

// starts unleash client each time user logs in
client.start()

client.on("initialized", () => {
if (__DEV__) {
console.log("Unleash initialized")
Expand Down Expand Up @@ -51,7 +54,7 @@ export function UnleashProvider({ children }: { children?: React.ReactNode }) {
client.stop()
}
}
}, [unleashEnv, isHydrated])
}, [unleashEnv, isHydrated, userId])

const onForeground = useCallback(() => {
forceFetchToggles(unleashEnv)
Expand Down
1 change: 0 additions & 1 deletion src/app/utils/experiments/unleashClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function getUnleashClient(props?: {
envBeingUsed = props?.env
}
unleashClient = createUnleashClient(nullToUndef(props?.userId))
unleashClient.start()
}
return unleashClient
}
Expand Down

0 comments on commit 4529b08

Please sign in to comment.