I have a custom Wix profile page (made with Velo) that displays the user's information. To get that information, I have to query a database, and to query that database I have to get the currently logged in user's login email address. Fortunately, Wix has an API for that, currentMember. However, using currentMember.getMember() is returning undefined on the profile page. But after I reload the profile page, it returns an object with the correct member data (including the email I need). Why is this happening? Another thing I noticed is that I'm getting the following error in the console:
I was thinking that since the error said the URL was preloaded, perhaps the page loaded before I logged in, and thus the member object being returned is undefined, since the user hadn't logged in yet.
Here is the code I used to log the member object to the console:
import { currentMember } from 'wix-members';
$w.onReady(function () {
currentMember.getMember()
.then((member) => {
console.log(member);
});
}
And this was logging undefined, but when I reload, it gives the correct info.