applySessionToken( )


Logs the current member into the site using the given session token.

The applySessionToken() function returns a Promise that resolves when the given session token is applied and the current member is logged into the site.

You receive a session token from the following wix-members-backend functions:

Pass the returned session token to your page code and apply it by calling applySessionToken() to complete the process started by one of the above functions.

Method Declaration
Copy
function applySessionToken(sessionToken: string): Promise<void>;
Method Parameters
sessionTokenstringRequired

Session token to apply.

JavaScript
import { authentication } from "wix-members-frontend"; // ... authentication.applySessionToken(sessionToken).then(() => { console.log("Member logged in."); });
Did this help?

changePassword( )


Changes the member's password to a new one, using a reset token.

Important:

This function is in Developer Preview and is subject to change.

The changePassword() function returns a Promise that resolves when the password is successfully changed, or rejects with an error if the operation fails.

Method Declaration
Copy
function changePassword(newPassword: string, token: string): Promise<void>;
Method Parameters
newPasswordstringRequired

New password the member wants to set. Minimum 6 characters.


tokenstringRequired

Reset token received in the email triggered by the sendResetPasswordEmail() function.

Change the member's password using a reset token
JavaScript
import { authentication } from "wix-members-frontend"; authentication .changePassword(newPassword, token) .then(() => { console.log("Password changed successfully"); }) .catch((error) => { console.error("Error changing password:", error); });
Did this help?

loggedIn( )


Indicates whether the site visitor is a logged-in member.

The loggedIn() function returns a boolean value indicating whether the current visitor is logged in as a site member.

If a member is logged in, loggedIn() returns true. Otherwise, loggedIn() returns false.

Method Declaration
Copy
function loggedIn(): boolean;
Request
This method does not take any parameters
Returns
Return Type:boolean
JavaScript
import { authentication } from "wix-members-frontend"; // ... const isLoggedIn = authentication.loggedIn(); if (isLoggedIn) { console.log("Member is logged in"); } else { console.log("Member is not logged in"); }
Did this help?

login( )


Logs a registered member in with an email and password.

The login() function returns a Promise that resolves when the member with the specified email address and password is logged in.

The login() function only works with existing members. To register a new member use the register() function.

Note:

  • The APIs in wix-members-frontend are only partially functional when previewing your site. View a published version of your site to see their complete functionality.
Method Declaration
Copy
function login(email: string, password: string): Promise<void>;
Method Parameters
emailstringRequired

Login email address.


passwordstringRequired

Member password.

JavaScript
import { authentication } from "wix-members-frontend"; // ... authentication .login(email, password) .then(() => { console.log("Member is logged in"); }) .catch((error) => { console.error(error); });
Did this help?

logout( )


Logs the current member out of the site.

The logout() function logs the current member out of the site.

Notes:

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

  • The APIs in wix-members-frontend 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.

Method Declaration
Copy
function logout(): void;
Request
This method does not take any parameters
JavaScript
import { authentication } from "wix-members-frontend"; // ... authentication.logout();
Did this help?

onLogin( )


Sets the function that runs when a member logs in.

The onLogin() event handler runs when a member logs into your site.

onLogin receives a currentMember object for the logged-in member, which contains the CurrentMember methods you can use to retrieve the member's information.

Usually, you want to call onLogin() in the masterPage.js file in the code editor so that the onLogin() event handler runs no matter which page a member uses to log in.

Notes:

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

  • The APIs in wix-members-frontend 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.

Method Declaration
Copy
function onLogin(handler: function): void;
Method Parameters
handlerfunctionRequired

handler(currentMember: CurrentMember): void Function name or expression to run when a member logs in.

Run code when a member logs in
JavaScript
import { authentication } from "wix-members-frontend"; // ... authentication.onLogin(async (member) => { const loggedInMember = await member.getMember(); const memberId = loggedInMember._id; console.log(`Member ${memberId} logged in:`, loggedInMember); });
Did this help?