Display Logged In Username on Screen

Anyone know how to get the Current User firstName from the WIX members list for the user that is currently logged in ?

Note i’m not wanting the userId, i’m wanting the firstName so that i can display it on screen.

Can’t see what i’m looking for in that link

Hi Mike:

There is currently no way to get at user information from the CRM using Wix Code. The only way to do this is if you directly manage the registration of users to the site.
This can be done using wix-users.register and keeping a local copy of the registration information.

If you follow this tutorial:

and instead of (or in addition to) using wixUsers.promptLogin( {“mode”: “login”} ) to get the logged in user information you can create your own subscription page that sets up Member information in a Members data collection. wix-users.register uses the ContactInfo that tom.tomy references above to update the crm. You will need to maintain a copy of the information in your members data collection. When your user logs in you can use wix-users current user to access you local Members data collection and pull the related user information for you to display on the loaded page.

Hope this helps.
Steve

My preference is to pull the name from the CRM as i don’t want to run two seperate lists. I would have thought there was a way to do it as WIX seem to be able to do it for the “WIX login app”. When a user logs into a website the text for the “WIX login app” will change from “login” to the “users firstName & lastName”. Are they running some code that we can not ?

Hi Mike

Most if the code APIs are fairly new. The way the login functionality works predates the api. I have spoken to the crm team and shared emails with them suggesting that they consider a more REST like CRUD approach to their core apis that access app functionality.

In the meantime the methodology I suggested above is probably your only option If you need flexibility. The current apis only allow data to be sent to the crm not read from it.

Steve

Thanks Stcroppe, some info can be read such as user.Id, useremail,etc.

import wixUsers from 'wix-users';



let user = wixUsers.currentUser;

let userId = user.id;          
let isLoggedIn = user.loggedIn; 

user.getEmail()
 
user.getRoles()

But no firstName…

Yes - it is this data that you would use to manage your own Members data collection and keep track of user name and other information that you need for now.

@stcroppe members passwords aren’t encrypted if i were to create a Members data collection

@mikemoynihan99 You can still use the wix-users api to log in and out and manage password info. The difference is that anything else you can control access to from your own data collection. So after the user logs into your page you can use wix-users.currentUser . This tells you if they are logged in or not and gives you their ID. You can then use this id to read their details from the Member database and allow them to update as needed.

@stcroppe thanks for the info

I am very new to WIX and in playing around, I wanted to put the currently logged on user’s name into a field. I created a simple database, using the standard logon which creates a file containing user information called Members/PrivateMembersData . Stands to reason you can create a get function to pull out any data from any collection, using key which is _ID field (userid) in this collection. Here’s the code to get the current id, and then use in a query to pull out the user’s name. You could get the other fields with this too. Plug it into a form and run it. It should log the user’s name on the console if all goes well. It worked for me but then I am just dabbling around. You might have to mess with permissions to make sure it works for other users. Enjoy.

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;

$w.onReady(function () {
let name = “No user”
let user = wixUsers.currentUser;
let userid = user.id

let options = {
“suppressAuth”: true,
“suppressHooks”: true
};

// pull name out of PrivateMembersData (file created by default logon)
console.log(userid)
wixData.get( “Members/PrivateMembersData”,userid , options)
.then( (results) => {
let item = results;
name = item.name // pull out the name (by field “name”)
console.log(name)
})
.catch( (err) => {
let errorMsg = err;
});
});

Yes, however that is with using the Wix Members app within your site and having the PrivateMembersData collection added due to it.

However, if you’ve gone down the route of creating your own profile and update profile pages as per like from the tutorial and what Steve mentions too.

You can simply pull the users name directly fron the members dataset or show whatever other info you want to.

I’ve used both with custom lightboxes for signup and login and have user inputs on signup lightbox that get saved to CRM for Contacts and then when the user is approved, all their inputs are added to the members dataset so that their profile page is populated with that info already, otherwise it would be blank apart from email.

I also have a basic text element which is linked to the firstname in members dataset, so that it shows the site members name on the page, no need for the code.

Obviously if you are happy with the Wix Members app My Account page etc, then you don’t need to do the seperate dynamic pages for own profile.