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(): Promise<boolean>;
Request
This method does not take any parameters
Returns
Return Type:Promise<boolean>
JavaScript
import { authentication } from "@wix/site-members"; // ... const isLoggedIn = await authentication.loggedIn(); if (isLoggedIn) { console.log("Member is logged in"); } else { console.log("Member is not logged in"); }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

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/site-members"; // ... authentication .login(email, password) .then(() => { console.log("Member is logged in"); }) .catch((error) => { console.error(error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

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(): Promise<void>;
Request
This method does not take any parameters
JavaScript
import { authentication } from "@wix/site-members"; // ... authentication.logout();
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

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): Promise<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/site-members"; // ... authentication.onLogin(async (member) => { const loggedInMember = await member.getMember(); const memberId = loggedInMember._id; console.log(`Member ${memberId} logged in:`, loggedInMember); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

onLogout( )


Sets the function that runs when a member logs out.

Use the onLogout() function for code you want to run after a member logs out from your site.

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

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 onLogout(handler: function): Promise<void>;
Method Parameters
handlerfunctionRequired

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

Run code when a member logs out
JavaScript
import { authentication } from "@wix/site-members"; // ... authentication.onLogout(() => { console.log("Member logged out"); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

promptForgotPassword( )


Prompts the current site visitor with a password reset modal.

The promptForgotPassword() function returns a Promise that resolves when the visitor submits the Create New Password form.

If the visitor cancels the form without submitting it, the Promise is rejected.

promptForgotPassword() cannot be called before the page is ready.

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.

  • If you return or await the promptForgotPassword() function when calling from onReady(), the page will be prevented from loading. To handle the resolved promise, use .then() and .catch().

Method Declaration
Copy
function promptForgotPassword(): Promise<void>;
Request
This method does not take any parameters
Prompt the visitor with a password reset
JavaScript
import { authentication } from "@wix/site-members"; // ... authentication .promptForgotPassword() .then(() => { console.log('Sending "forgot password" email'); }) .catch((error) => { console.error(error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

promptLogin( )


Prompts the current visitor to log in as a site member.

The promptLogin() function returns a Promise that resolves when the login has completed.

If the visitor cancels the form without logging in, the Promise is rejected.

The promptLogin() function cannot be called before the page is ready.

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.

  • If you return or await the promptLogin() function when calling from onReady(), the page will be prevented from loading. To handle the resolved promise, use .then() and .catch().

Method Declaration
Copy
function promptLogin(options: LoginOptions): Promise<void>;
Method Parameters
optionsLoginOptions

The options that determine how the login dialog box appears.

Prompt the current visitor to log in
JavaScript
import { authentication } from "@wix/site-members"; // ... // Sample options value: // { // mode: 'login', // modal: true // } authentication .promptLogin(options) .then(() => { console.log("Member is logged in"); }) .catch((error) => { console.error(error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

register( )


Registers a new site member.

The register() function returns a Promise that resolves to a RegistrationResult object when the member is registered or pending registration.

The specified password must be between 4 and 100 ASCII characters.

See New Members to learn about verifying emails and approving members.

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 member data in the resolved Promise includes custom fields from your site's contacts only if they are added to your site members in your dashboard.

  • When a new member signs up using an email address that's already in your site's Contact List, a notification is displayed and a confirmation email is sent to the new member. To register a member without displaying the notification, use register() from wix-members-backend (this does not suppress the confirmation email).

  • When your site's member signup settings are set to automatic approval, calling register() from wix-members-frontend (in page code) is as secure as calling register() from wix-members-backend (in backend code), unless you are implementing custom site registration using Velo forms. However, when registration is set to manual approval, calling register() from wix-members-backend allows you to build more secure approval flows by keeping tokens hidden from the frontend.

Method Declaration
Copy
function register(
  email: string,
  password: string,
  options: RegistrationOptions,
): Promise<RegistrationResult>;
Method Parameters
emailstringRequired

Email address the new member will use to log in.


passwordstringRequired

Password to assign to the new member. Must be 4 to 100 ASCII characters.


optionsRegistrationOptions

Registration options.

Returns
Return Type:Promise<RegistrationResult>
Register a site member

This example contains a custom field, "Hobby".

JavaScript
import { authentication } from "@wix/site-members"; // ... /* Sample options value: * { * contactInfo: { * firstName: 'Juan', * lastName: 'Doe', * picture: 'https://static.parastorage.com/unpkg-semver/communities-blog-statics/assets/wix-logo.png', * hobby: 'Football' * }, * privacyStatus: "PRIVATE" * } */ authentication .register(email, password, options) .then((registrationResult) => { const status = registrationResult.status; if (status === "PENDING") { // When the site is configured for manual approval, // status is "PENDING" and approvalToken is returned. const approvalToken = registrationResult.approvalToken; console.log( "Member registered and waiting for approval:", registrationResult, ); } else { // When the site is configured for automatic approval, // status is "ACTIVE" and the member is approved and logged in. // To prevent logging in the member automatically, // use the backend function: wix-members-backend.authentication.register() console.log("Member registered and logged in:", registrationResult); } }) .catch((error) => { console.error(error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

resendVerificationCodeEmail( )


Resends a one-time password (OTP) for email verification.

Important:

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

The resendVerificationCodeEmail() function returns a Promise that resolves when the email is successfully sent, or rejects with an error if the operation fails.

Method Declaration
Copy
function resendVerificationCodeEmail(): Promise<void>;
Request
This method does not take any parameters
Email a member with a link to verify their email
JavaScript
import { authentication } from "@wix/site-members"; authentication .resendVerificationCodeEmail() .then(() => { console.log("Verification code email resent"); }) .catch((error) => { console.error("Error resending verification email:", error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?