Hi all
I found the following which might be a mistake of mine or a discrepancy.
In the tutorial at https://auth0.com/docs/libraries/auth0-single-page-app-sdk in section “Login and get user info” I found the following code:
// or with promises
document.getElementById(‘login’).addEventListener(‘click’, () => {
auth0.loginWithRedirect({
redirect_uri: ‘http://localhost:3000/’
}).then(token => {
//logged in. you can get the user profile like this:
auth0.getUser().then(user => {
console.log(user);
});
});
});
I tried this in an app of mine, but sending the user and the token to the console shows “undefined”. Going to the reference document (https://auth0.github.io/auth0-spa-js/classes/auth0client.html#loginwithredirect) I found, in the last line, it Returns Promise<void>
, which justifies the above inconsistency.
Am I missing something or the tutorial is wrong?
Anyway, the solution for my issue was to move the code in the “then” block after a “handleRedirectCallback” in the callback resource. No guarantee, I’m still working on it .
EDIT: I forgot to mention that I was using the Brave browser (
Version 1.41.96 Chromium: 103.0.5060.114) for my tests, which seems to be significant. Using Firefox instead (V 102.0) the user information is available after the loginWithRedirect
. However, the token
is undefined.
EDIT and closing. Forgive me. Probably I just messed up the auth0-spa-js and auth0-llibraries. I am not able anymore to reproduce the situation.