currentMember.getMember ... getting Failed to Fetch

I’m trying to fill an input field with a login email… what am I missing here?
The error message I’m getting is “Failed to Fetch”

The member has to be logged in to see the page this is on.
The input filed is named inputLoginEmail

import { currentMember } from 'wix-members';

$w.onReady(function () {

    currentMember.getMember()
        .then((member) => {
            const thisID = member._id
            const thisFullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;

            const thisLoginEMail = member.loginEmail;
            $w('#inputLoginEmail').value = thisLoginEMail;

            return member;
        })
        .catch((error) => {
            console.error(error);
        });

});

I had some errors using this function, this is the way I got it to work.
I created a function in the backend like this:

import { currentMember } from 'wix-members-backend'

export function myGetCurrentMemberFunction() {
  let options = {
    fieldsets: ['FULL'],
  }
  return currentMember
    .getMember(options)
    .then(member => member)
    .catch(error => error)
}

Then I imported it in the front end like this:

import { myGetCurrentMemberFunction } from 'backend/members'

$w.onReady(async () => {
  user = await myGetCurrentMemberFunction()
  console.log(user) //Check the user here.
})

Or doing the same way directly on front-end…

Start this function after login → onLogin-Event…

function get_CurrentMember() {
    let options = {fieldsets: [ 'FULL' ]}
    currentMember.getMember(options)
    .then((member) => {console.log("Member: ", member);
        const memberID = member._id; console.log("Member-ID: ", memberID)
        const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`; console.log(fullName);
        return member;
    })
    .catch((err) => {console.error(err);});
}

This is how it looks like what you will get…

But i would also recommend to do this on backend like Bruno already mentioned it.

Some related stuff (information)…
https://www.wix.com/velo/forum/coding-with-velo/authentication-onlogin-doesn-t-return-member-id

I tried your solution and seem not working. Have you run it. First I had to remove the await function. Then when I run it I receive an empty object.

Seems like there is a known issue in the new members/contacts API

Read the following post…

Hi all! I was having a similar issue trying to beforeInsert() member data into a new collection using a data.js file on the backend. I was FINALLY able to get it to work! The key was cleaning up all my promises (since all export functions on the backend are promise-based). For more info on how best to use member data on the backend, this article that hackernoon posted on velo promises was absolutely GOLDEN!! https://hackernoon.com/velo-promises-in-action-key-tips-to-call-the-asynchronously-run-functions-y52633kd

Thank you @hackernoon!