CodeAPI

User

A site user.

Table of Contents

PROPERTIES

?
Store values associated with an object.
idGets the user's ID.
loggedInIndicates whether the user is logged in or not.
roleDeprecated: Gets the user's role.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
PricingPlanAn object returned by the getPricingPlans() function representing a user's pricing plans.
UserRoleAn object returned by the getRoles() function representing a user's roles.

id

Gets the user's ID.

Description

The unique ID of the user.

Note

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

get id(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the user's ID

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

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

loggedIn

Indicates whether the user is logged in or not.

Description

Gets one of the following:

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

Note

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

get loggedIn(): boolean
TYPE
?
The kind of data the property stores.
boolean

Examples

Get whether the user is logged in or not

let isUserLoggedIn = user.loggedIn;  // true

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

role

Deprecated: Gets the user's role.

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.

Note

The get role API was deprecated and replaced with getRoles() The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

get role(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the user's role

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

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

getEmail( )

Gets the email of the current user.

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.

Note

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

function getEmail(): Promise<string>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>

Fulfilled - The email address of the user that is logged in. Rejected - Message containing error that the current user is not logged in.

Examples

Get the user's email address

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

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

getPricingPlans( )

Gets the user's member pricing plan.

Description

The getPricingPlans() function returns a Promise that resolves to the pricing plansof the user that is logged in or rejects if the current user is not logged in.

Pricing plans

help you manage which site members can access which pages.

Note

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

function getPricingPlans(): Promise<Array<PricingPlan>>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Array<PricingPlan>>

Fulfilled - The user's pricing plans. Rejected - Error message.

Examples

Get a user's member pricing plans

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;
    let startDate = firstPlan.startDate;
    let expiryDate = firstPlan.expiryDate;
  } );

/* firstPlan:
 * {
 *   "name": "Gold",
 *   "startDate": Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time),
 *   "expiryDate": Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
 * }
 */

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

getRoles( )

Gets the user's member roles.

Description

The getRoles() function returns a Promise that resolves to the rolesof the user that is logged in or rejects if the current user is not logged in.

Member roles

help you manage which site members can access which pages.

Note

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

function getRoles(): Promise<Array<UserRole>>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Array<UserRole>>

Fulfilled - The user's roles. Rejected - Error message.

Examples

Get a user's roles

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

Get the current user's information

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

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

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

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;          // "Gold"
    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
  } );

PricingPlan

An object returned by the getPricingPlans() function representing a user's pricing plans.

See Also

getPricingPlans( )

Syntax

type PricingPlan = {
  name: string
  startDate: Date
  expiryDate: Date
}
MEMBERS
?
The kind of data the property stores.
name
string
The pricing plan's name.
startDate(Optional)
Date
The pricing plan's start date.
expiryDate(Optional)
Date
The pricing plan's expiry date.

Examples

Get a user's member pricing plans

user.getPricingPlans()
  .then( (pricingPlans) => {
    let firstPlan = pricingPlans[0];
    let planName = firstPlan.name;
    let startDate = firstPlan.startDate;
    let expiryDate = firstPlan.expiryDate;
  } );

/* firstPlan:
 * {
 *   "name": "Gold",
 *   "startDate": Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time),
 *   "expiryDate": Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
 * }
 */

UserRole

An object returned by the getRoles() function representing a user's roles.

See Also

getRoles( )

Syntax

type UserRole = {
  name: string
  description: string
}
MEMBERS
?
The kind of data the property stores.
name
string
Role name as defined in the site's dashboard or one of "Admin" or "Member".
description(Optional)
string
Role description, if defined in the site's dashboard.

Examples

Get a user's member roles

user.getRoles()
  .then( (roles) => {
    let firstRole = roles[0];
    let roleName = firstRole.name;                // "Role Name"
    let roleDescription = firstRole.description;  // "Role Description"
  } );