Introduction

To use the Authentication API, import {authentication} from the wix-members-backend module:

Copy
Did this help?

New Members

When a new member registers for an account on your site, they can't immediately login. They must be approved as a member (which can be set to automatic), and you may wish to have them verify their email.

You can edit these settings in your site's dashboard.

Email verification

You may want to check that a new member is using their own email address, not using someone else's or a fake email address.

To run this check, require members to verify their email address once they've signed up in one of the following ways:

  • In your site's dashboard, under Ask new members to confirm their email.
  • Using code. This example includes email verification through code.

Manual vs automatic approval

The register function behaves differently depending on your site's member signup settings.

Manual approval

When manual approval is enabled, everyone who signs up must then be approved. Immediately after signing up, a new member's status is "PENDING".

You can approve a new member by:

Automatic approval

When automatic approval is enabled, everyone who signs up is approved. Immediately after signing up, a new member's status is "ACTIVE".

They can immediately log in to the site, or you can log them in by passing the returned sessionToken to applySessionToken() from wix-members-frontend.

You can have more control of who can become a site member using custom site registration and Velo code.

If you are implementing code to automatically approve emails in a collection, make sure to set the collection Permissions to private and to never expose the collection in your frontend code.

Did this help?

approveByEmail( )


Approves a pending member using an email address.

The approveByEmail() function returns a Promise that resolves to a session token when the specified member is approved. The session token can be applied using the wix-members-frontend applySessionToken() function to log the member in.

A new member's status is "PENDING" when the site's membership policy is set to manual approval. To learn more about setting your site's membership approval policy, see Editing Your Member Signup Settings.

Method Declaration
Copy
Method Parameters
emailstringRequired

Login email address of the member to approve. Must belong to an existing member.

Returns
Return Type:Promise<string>
Approve a pending member using an email address

This example contains a backend function that approves a pending member using their email address. It returns a session token to be used in page code to log in the member who was just approved.

JavaScript
Did this help?

approveByToken( )


Approves a pending member using an approval token.

The approveByToken() function returns a Promise that resolves to a session token when the specified member is approved. Tokens must be approved within 30 hours of token creation.

A new member's status is "PENDING" when the site's membership policy is set to manual approval. To learn more about setting your site's membership approval policy, see Editing Your Member Signup Settings.

Use the approvalToken parameter returned from the register() function when calling approveByToken().

Method Declaration
Copy
Method Parameters
tokenstringRequired

Approval token returned by the register() function.

Returns
Return Type:Promise<string>

This example contains a backend function that approves a pending member using an approval token. It returns a session token to be used in page code to log in the member who was just approved.

JavaScript
Did this help?

blockByEmail( )


Blocks a member from logging in to the site.

The blockByEmail() function returns a Promise that resolves when the specified member is blocked.

To unblock the member and allow them to log in to the site, use approveByEmail().

Method Declaration
Copy
function blockByEmail(email: string): Promise<void>;
Method Parameters
emailstringRequired

Login email address of the member to block.

Block a member
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { authentication } from "wix-members-backend"; export const myBlockByEmailFunction = webMethod(Permissions.Anyone, (email) => { return authentication .blockByEmail(email) .then(() => { console.log("Email blocked from site membership"); }) .catch((error) => { console.error(error); }); });
Did this help?