wix-users.User

wix-users.User

A site user.

Contents

id Gets the user's ID.
loggedIn Indicates whether the user is logged in or not.
role Gets the user's role.
getEmail( ) Gets the email of the current user.
id

id

Gets the user's ID.

Syntax

get id(): String

Description

The unique ID of the user.

Type

String

Examples

Get the user's ID

bGV0IHVzZXJJZCA9IHVzZXIuaWQ7ICAvLyAicjVnZHVpY21lLTZmZW0tNDg1ai1kanJlLTQ4NDNoNGtqYzM0OSIK
let userId = user.id;  // "r5gduicme-6fem-485j-djre-4843h4kjc349"

Get the current user's information

aW1wb3J0IHdpeFVzZXJzIGZyb20gJ3dpeC11c2Vycyc7CgovLyAuLi4KCmxldCB1c2VyID0gd2l4VXNlcnMuY3VycmVudFVzZXI7CgpsZXQgdXNlcklkID0gdXNlci5pZDsgICAgICAgICAgIC8vICJyNWNtZS02ZmVtLTQ4NWotZGpyZS00ODQ0YzQ5IgpsZXQgaXNMb2dnZWRJbiA9IHVzZXIubG9nZ2VkSW47IC8vIHRydWUKbGV0IHVzZXJSb2xlID0gdXNlci5yb2xlOyAgICAgICAvLyAiTWVtYmVyIgoKdXNlci5nZXRFbWFpbCgpCiAgLnRoZW4oIChlbWFpbCkgPT4gewogICAgbGV0IHVzZXJFbWFpbCA9IGVtYWlsOyAgICAgIC8vICJ1c2VyQHNvbWV0aGluZy5jb20iCiAgfSApOwo=
import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role;       // "Member"

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
  } );
loggedIn

loggedIn

Indicates whether the user is logged in or not.

Syntax

get loggedIn(): Boolean

Description

Gets one of the following:

  • true — The user is logged in.
  • false — The user is not logged in.

Type

Boolean

Examples

Get whether the user is logged in or not

bGV0IGlzVXNlckxvZ2dlZEluID0gdXNlci5sb2dnZWRJbjsgIC8vIHRydWUK
let isUserLoggedIn = user.loggedIn;  // true

Get the current user's information

aW1wb3J0IHdpeFVzZXJzIGZyb20gJ3dpeC11c2Vycyc7CgovLyAuLi4KCmxldCB1c2VyID0gd2l4VXNlcnMuY3VycmVudFVzZXI7CgpsZXQgdXNlcklkID0gdXNlci5pZDsgICAgICAgICAgIC8vICJyNWNtZS02ZmVtLTQ4NWotZGpyZS00ODQ0YzQ5IgpsZXQgaXNMb2dnZWRJbiA9IHVzZXIubG9nZ2VkSW47IC8vIHRydWUKbGV0IHVzZXJSb2xlID0gdXNlci5yb2xlOyAgICAgICAvLyAiTWVtYmVyIgoKdXNlci5nZXRFbWFpbCgpCiAgLnRoZW4oIChlbWFpbCkgPT4gewogICAgbGV0IHVzZXJFbWFpbCA9IGVtYWlsOyAgICAgIC8vICJ1c2VyQHNvbWV0aGluZy5jb20iCiAgfSApOwo=
import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role;       // "Member"

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
  } );
role

role

Gets the user's role.

Syntax

get role(): String

Description

Gets one of the following roles:

  • "Admin" — The owner of the site.
  • "Member" — A user who is logged in.
  • "Visitor" — A user who is not logged in.

Type

String

Examples

Get the user's role

bGV0IHVzZXJSb2xlID0gdXNlci5yb2xlOyAvLyAiTWVtYmVyIgo=
let userRole = user.role; // "Member"

Get the current user's information

aW1wb3J0IHdpeFVzZXJzIGZyb20gJ3dpeC11c2Vycyc7CgovLyAuLi4KCmxldCB1c2VyID0gd2l4VXNlcnMuY3VycmVudFVzZXI7CgpsZXQgdXNlcklkID0gdXNlci5pZDsgICAgICAgICAgIC8vICJyNWNtZS02ZmVtLTQ4NWotZGpyZS00ODQ0YzQ5IgpsZXQgaXNMb2dnZWRJbiA9IHVzZXIubG9nZ2VkSW47IC8vIHRydWUKbGV0IHVzZXJSb2xlID0gdXNlci5yb2xlOyAgICAgICAvLyAiTWVtYmVyIgoKdXNlci5nZXRFbWFpbCgpCiAgLnRoZW4oIChlbWFpbCkgPT4gewogICAgbGV0IHVzZXJFbWFpbCA9IGVtYWlsOyAgICAgIC8vICJ1c2VyQHNvbWV0aGluZy5jb20iCiAgfSApOwo=
import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role;       // "Member"

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
  } );
getEmail( )

getEmail( )

Gets the email of the current user.

function getEmail(): Promise<String>

Description

The getEmail() function returns a Promise that resolves to the email address of the user that is logged in or rejects if the current user is not logged in.

Return Value

Returns a Promise

On fulfillment String The email address of the user that is logged in.
On rejection String Message containing error that the current user is not logged in.

Examples

Get the user's email address

dXNlci5nZXRFbWFpbCgpCiAgLnRoZW4oIChlbWFpbCkgPT4gewogICAgbGV0IHVzZXJFbWFpbCA9IGVtYWlsOyAvLyAidXNlckBzb21ldGhpbmcuY29tIgogIH0gKTsK
user.getEmail()
  .then( (email) => {
    let userEmail = email; // "user@something.com"
  } );

Get the current user's information

aW1wb3J0IHdpeFVzZXJzIGZyb20gJ3dpeC11c2Vycyc7CgovLyAuLi4KCmxldCB1c2VyID0gd2l4VXNlcnMuY3VycmVudFVzZXI7CgpsZXQgdXNlcklkID0gdXNlci5pZDsgICAgICAgICAgIC8vICJyNWNtZS02ZmVtLTQ4NWotZGpyZS00ODQ0YzQ5IgpsZXQgaXNMb2dnZWRJbiA9IHVzZXIubG9nZ2VkSW47IC8vIHRydWUKbGV0IHVzZXJSb2xlID0gdXNlci5yb2xlOyAgICAgICAvLyAiTWVtYmVyIgoKdXNlci5nZXRFbWFpbCgpCiAgLnRoZW4oIChlbWFpbCkgPT4gewogICAgbGV0IHVzZXJFbWFpbCA9IGVtYWlsOyAgICAgIC8vICJ1c2VyQHNvbWV0aGluZy5jb20iCiAgfSApOwo=
import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role;       // "Member"

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
  } );