Relative timing for wix-users onLogin and page onReady

I need to put in some initialization code that runs each time a member logs in.
I also need to run some code in the onReady handler for certain member pages. The onReady code MUST be executed after the onLogin code has been run - I need to have a properly initialized member before I can proceed.
The documentation here https://www.wix.com/corvid/reference/wix-users.html#onLogin
suggests that you can put the onLogin code in the Site tab so it is executed on every page. Perfect!
But, it also says

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.
Clearly, I’d like to run the onLogin code in the Site tab FIRST before I run the onReady code for the page. This seems to be a contradiction. Should I assume that the onLogin code will run before onReady AND that the wix-users API will be usable? Or, should I put an onLogin handler in every onReady page handler for the pages that need access to the wix-users API? If the latter, then why recommend we put the onLogin handler in the site tab?

Hey Martin,

You can enter the code inside the onReady() in the site tab.
It will run after the page is ready on every page of the site.
The code in site tab run before the code in page but if it inside the onReady(), it will run after the page is ready before the onReady() of the page.

In order it to work you should import wixUsers before the onReady();

The code in the site tab should look like this:

import wixUsers from 'wix-users';

$w.onReady(function () {
    wixUsers.onLogin((user) => {
     //Do something
    });
});

Best

Binyamin

Sounds like it might work, but it doesn’t. I put a console.log inside the onLogin handler but it doesn’t get executed. I suspect it doesn’t fire because the page loads only after the user has logged in. Page not loaded means no onLogin handler, which means no user initialization.
Even if it did work I would have to put in wait logic on each page, because the page onReady doesn’t wait for the site onReady to finish. And if I’m putting in wait logic, I may as well call the user initialization directly. I was trying to simplify the logic in each page’s onReady handler. I could see some use for the site code, just not my scenario.