User object not loading after login

Hi,

read-only link: Webflow - cheffle v1

published site: https://cheffle-v1.webflow.io/

I’ve recently noticed that, after logging in, the user object does not load any data (like stated in the docs at /sa5-user-accounts/get-logged-in-user-info/the-user-object/the-user-object-lifecycle).

The user object and all custom fields etc are only loaded after:

  • Closing all tabs and reopening them (still logged in)
  • Going to the user account page and saving changes (even when you’ve changed nothing)

This happens after fresh account creation, but also after logging in to an existing account in a fresh session.

I need to be able to fetch user information immediately after a login, so that I can send the user-id (inputted into a custom field) towards my Stripe checkout session.

This is the code in my head

<!-- Sygnal Attributes 5 | User Accounts --> 
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sygnaltech/webflow-util@5.4.6/dist/css/webflow-membership.css"> 
<script defer src="https://cdn.jsdelivr.net/gh/sygnaltech/webflow-util@5.4.6/dist/nocode/webflow-membership.js"></script>
<script>
window.sa5 = window.sa5 || [];
window.sa5.push(['getMembershipConfig', 
  (config) => {
    // Apply any configuration settings here
    // such as access groups
    return config;
  }]);
</script>

and this is the code in my page (e.g. /kookplannen/italiaanse-avond)

<script>
window.sa5 = window.sa5 || [];
window.sa5.push(['userInfoChanged', 
  (user) => {
    console.log('SA5 userInfoChanged triggered');

    // Globale variabelen om gebruikersinformatie op te slaan
    window.userId = null;
    window.userEmail = null;
    window.userName = null;

    // Check of de custom fields geladen zijn
    if (user.user_data_loaded.custom_fields) {
        console.log('Custom fields loaded');

        // Sla de benodigde informatie op in globale variabelen
        window.userId = user.data["user-id"]; 
        window.userEmail = user["email"]; 
        window.userName = user["name"]; 

        console.log('User ID:', window.userId);   
        console.log('User Email:', window.userEmail);
        console.log('User Name:', window.userName);
    } else {
        console.error('User data not available');
    }
  }
]);
</script>

Any idea how to solve this?

I believe I figured out the issue. It happens because of a referral page that redirects users back to the page they were on before logging in. This referral page checks a parameter in the URL and redirects the user accordingly.

The problem was that the redirect happened too quickly, before the user object had fully loaded. As a result, the user object wasn’t properly loaded on the new page after the redirect. A change in the user account page would then prompt the reload of the user object.

1 Like

Thanks for sharing @cheffle , we’re overloaded on projects here atm. Redirect script conflicts are possible but the main place that would be risky is;

  • during the login process, if it prevented SA5 from loading and capturing the login event
  • in a page where e.g. you want to redirect based on user info, you’d do the redirect in an SA5 callback, so that the user info loads first, and then the redirect occurs

Other redirect situations generally shouldn’t matter because whatever site page you eventually land on, SA5 will still load its data for the construction of that page.