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.
})
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