When Terra redirects to your site or app, post-auth success, we store the user_id and reference_id in the query parameters of the redirect, so you can get the user_id in sync from the current url (Terra redirects also support deep links and the query paramets should still be accessible)
Alternatively, you can set a reference_id when generating the widget which will also be sent with the auth_success payload and every following payload.