Advertisement
aaaaaghghghghgh

Braze changeUser usages

Jul 31st, 2024
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // AuthHelper.js
  2. export const setUserIdentifiers = async () => {
  3.   /** @type {import('amazon-cognito-identity-js').CognitoUser} */
  4.   const userData = getCurrentUser();
  5.   if (userData) {
  6.     const userId = userData?.username;
  7.     // ...
  8.     setUserIdentifierForBraze(userId);
  9.     // ...
  10.   }
  11. };
  12.  
  13. const setUserIdentifierForBraze = (userId) => {
  14.   Braze.changeUser(userId);
  15. };
  16.  
  17. export const refreshThirdPartyData = async () => {
  18.   try {
  19.     await setUserIdentifiers();
  20.   } catch (err) {
  21.     log.warn("refreshThirdPartyData", err.toString());
  22.   }
  23. };
  24.  
  25. // Startup.js
  26. const StartupManager = () => {
  27.   // this is called as part of our startup process
  28.   const finishSetupWithUser = useCallback(
  29.     async () => {
  30.       log.trace("[Startup] - Finish Setup With User Data");
  31.       log.trace("[Startup] - Set User Identifiers");
  32.       await setUserIdentifiers();
  33.       // ...
  34.     },
  35.     [
  36.       /* ... */
  37.     ]
  38.   );
  39.  
  40.   useNonInitialEffect(() => {
  41.     // If we cold started while offline but we're no longer offline
  42.     // then rerun authentication as well as third party connections
  43.     if (!isOffline) {
  44.       log.trace("Refresh Third Party Data");
  45.       const refreshUserData = async () => {
  46.         await refreshThirdPartyData();
  47.       };
  48.       refreshUserData();
  49.     }
  50.   }, [isOffline]);
  51. };
  52.  
  53. // SignInSignOutHelper.js
  54. export const signIn = async (opts) => {
  55.   try {
  56.     // ...
  57.     await setUserIdentifiers();
  58.     // ...
  59.   } catch (err) {
  60.     // ...
  61.   }
  62. };
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement