Persistant Wix-Authentication / Wix-Members-API issue

Hello Gal, i tried to understand your suggested- checkpoint-1 and also followed your suggestion and made sure, that the USER/MEMBER is first logged-in, before i start to ask for member-data.

…you should have an “await” before the loginMember() call to make sure he did logged in, otherwise both calls for login and getting member are being fired in parallel. Let me know if it helped.

This is the code for it. Just a little bit modofied-version of the same code, like shown in the VELO-API-DOCs… (using the following two APIs)…

1) https://www.wix.com/velo/reference/wix-members/authentication/login
2) https://www.wix.com/velo/reference/wix-members/currentmember/getmember

import { authentication } from 'wix-members';
import { currentMember } from 'wix-members';

$w.onReady(function () {
    $w('#btnLogin').onClick(async () => {
        const email = $w('#inpEmail').value;
        const password = $w('#inpPassword').value;
        try {
            await authentication.login(email, password); console.log('Member is logged in');
            let member = await getMember(); console.log("Member: ",member);
        } 
        catch (error) {console.error(error);}
    });
});



function getMember() {console.log("GetMember-Function started to get the current MEMBER and it's ID...")

let options={fieldsets: [ 'FULL' ]}

currentMember.getMember(options) //options
  .then((member) => {
    const id = member._id;
    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
    return member;
  })
  .catch((error) => {
    console.error(error);
  });
}

I made sure, that the USER is logged-in first, before the getMember()-function starts to collect/return → MEMBER-DATA.

Here you can see the RESUTL:

As we can clearly see → the login was done first, then the getMember()-function starts to get → MEMBER.

But all you get is → UNDEFINED.

Until here you will agree with me, when i say → i just followed the → EXAMPLE from the VELO-API-DOCs…

  1. STEP1: using → login -->wix-authentication-api, to log in user/member…
import { authentication } from 'wix-members';
2
3// ...
4
5$w('#login').onClick(async () => {
6  const email = $w('#email').value;
7  const password = $w('#password').value;
8
9  try {
10    await authentication.login(email, password);
11    console.log('Member is logged in');
12  } catch (error) {
13    console.error(error);
14  }
15});
  1. STEP2: using–> getMember() → wix-currentMember-api, to get Member-Data.
import { currentMember } from 'wix-members';
2
3// ...
4
5// Sample options value:
6// {
7//   fieldsets: [ 'FULL' ]
8// }
9
10currentMember.getMember(options)
11  .then((member) => {
12    const id = member._id;
13    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
14    return member;
15  })
16  .catch((error) => {
17    console.error(error);
18  });
19
20/* Returned member object:
21 * {
22 *   "_id": "f32cbc51-a331-442b-86c2-2c664613e8b9",
23 *   "_createdDate": "2021-08-02T23:14:42Z",
24 *   "_updatedDate": "2021-08-02T23:14:58.345Z",
25 *   "lastLoginDate": "2021-08-12T19:46:33Z",
26 *   "loginEmail": "claude.morales@example.com",
27 *   "contactId": "f32cbc51-a331-442b-86c2-2c664613e8b9",
28 *   "status": "APPROVED",
29 *   "privacyStatus": "PRIVATE",
30 *   "activityStatus": "ACTIVE",
31 *   "profile": {
32 *     "nickname": "Claude Morales",
33 *     "slug": "claudemorales"
34 *   },
35 *   "contactDetails": {
36 *     "firstName": "Claude",
37 *     "lastName": "Morales",
38 *     "phones": [
39 *       "0747-769-460"
40 *     ],
41 *     "emails": [
42 *       "claude.morales@example.com"
43 *     ],
44 *     "addresses": [
45 *       {
46 *         "country": "GB"
47 *       },
48 *       {
49 *         "id": "f0f4d905-488d-44db-9080-fc29078cfad5",
50 *         "addressLine": "9373 Park Avenue",
51 *         "addressLine2": "Berkshire",
52 *         "city": "Ely",
53 *         "subdivision": "GB-ENG",
54 *         "country": "GB",
55 *         "postalCode": "PD50 8EU"
56 *       }
57 *     ],
58 *     "customFields": {}
59 *   }
60 * }
61 */

And while i already wanted to give up, because i could not find any solution and always got → UNDEFINED as result (and i really wanted to understand where i have had to put in a further → AWAIT ← like you mentioned it…

…and then…

!!! I GOT IT !!!

:grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl::grin::rofl:

But now it’s the question → was it my fault? :thinking::thinking::thinking::thinking::thinking::thinking::thinking::thinking::thinking::thinking::thinking:
I just was following the examples of the provided → currentMember-API

So what is my conclusion now?! ->> The API is wrong?! Or at least the API is for sure → incomplete !!! Why ? → because a → return ← is missing in the provided example, to make all the login-process work well !!!

I will mark the missing code-part in the provided VELO-EXAMPLE…

import { currentMember } from 'wix-members';
2
3// ...
4
5// Sample options value:
6// {
7//   fieldsets: [ 'FULL' ]
8// }
9
10 return currentMember.getMember(options)
11  .then((member) => {
12    const id = member._id;
13    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
14    return member;
15  })
16  .catch((error) => {
17    console.error(error);
18  });

After adding the return to the (not really working code) → it solved the issue.
So now you don’t need the onLogin-Function anymore, to get it working!

!!! PROBLEM with the missing return-data → SOLVED !!!

And now to you Gal: :grin:

If you ask me, if your suggestion helped me:
Yes indeed, it helped me, even if it was not the → await i was missing, but it let me orverthink the whole situation once again. And the result was about 25-different tries to solve the issue (until it made → boom in my

If you ask me if the provided login-user-interface fits my expectations:

  1. authentication.login() not returning any ID: in the docs, we declare that the login() function will return void once the login process is done. Note that it’s aligned with the former wix-users login() behavior, which also returned void.

Till here yes, everything is ok, with the provided API. And me as → USER<-- am also OK with the fact → that the → login()-function of the → authentication-API, gives me a → VOID ← as RESULT after(or during) login-process.

But in the VELO-API-Docs it perhaps also should be mentioned, that you also will need the following API…

…to get your login working (just as a little helping hint).

I know good experienced coder will find their way to …

…but the unexperienced will have problems to work with the example of the provided API-description and the API itself, to get the RIGHT-RESULT.

This intentional decision wasn’t made to cause you any frustration :blush: In the time of working on this API, we believed that due to performance considerations,…
Frustrating? → Yes, maybe! Especialy as i already mentioned → for the less experienced coders, this will be very frustrating, to not be able to get the right working result. For those like me → i will always find a workaround (ok → ALMOST ALWAYS xDDDDD) :sweat_smile:

it’d be better to leave the developer the choice on whether he would like to query for the member’s details or not
Here you are talking about the → options???
let options={fieldsets: [ ‘FULL’ ]}//options

If so, no i am totaly ok with the new working-style of the API, i see it as an → IMPROVEMENT ←

We’re definitely open to rethinking this design decision, and will do so. Can you please share more details on how the ID (or other member details) may serve you? I would like to understand your use-case better.
Since i could find the right solution for the issue, for me everything now makes sense!

My only wish would be → to UPDATE the VELO-API-DOCs!

So, at the end it was just one little code missing code-part, which was not mentioned in the API-Example, what caused all that trouble ???

About:
4. You mentioned there may be an issue with register(). Can you elaborate on what’s not working as expected there?

Oh, yeah there was a post i have seen once, but don’t know if i can find it again. Will come back to it, when i remember the issue :sweat_smile::sweat_smile::sweat_smile::sweat_smile:

And at last but not least → I also would ask all the other users & Velo-Masters, who probably have read this post for their opinion, or even corrections.

What do they think. All provided material here → is just out of my personal point of view.
Maybe other, see it defferent.

Let’s talk about it :laughing::wink: