> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: register(email: string, password: string, options: RegistrationOptions)

# Method package: wixMembersBackend

# Method menu location: wixMembersBackend --> Authentication --> register

# Method Link: https://dev.wix.com/docs/velo/apis/wix-members-backend/authentication/register.md

# Method Description:

Registers a new site member.

The `register()` function returns a Promise that resolves to a `RegistrationResult`
 object when the member is either registered or pending registration.

 The specified `password` must be between 4 and 100 ASCII characters.

 See [New Members](https://dev.wix.com/docs/velo/api-reference/wix-members-backend/authentication/new-members.md) to learn about verifying emails and approving members.
 
 > **Notes:**
 >
 > - 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](https://support.wix.com/en/article/customizing-your-member-profile-fields).
 >
 > - When your site's member signup settings are set to [automatic approval](https://dev.wix.com/docs/velo/api-reference/wix-members-backend/authentication/new-members.md#automatic-approval), 
 >   calling [`register()`](https://dev.wix.com/docs/velo/api-reference/wix-members-frontend/authentication/register.md) 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](https://dev.wix.com/docs/develop-websites/articles/code-tutorials/wix-members/enabling-custom-site-registration.md).
 >   However, when registration is set to [manual approval](https://dev.wix.com/docs/velo/api-reference/wix-members-backend/authentication/new-members.md#manual-approval),
 >   calling `register()` from wix-members-backend
 >   allows you to build more secure approval flows
 >   by keeping tokens hidden from the frontend.
 >
 > - Registering a member in the backend always creates a new contact,
 >   even if a contact with the specified `email` already exists.
 >   To avoid this behavior, use [`register()`](https://dev.wix.com/docs/velo/api-reference/wix-members-frontend/authentication/register.md)
 >   from `wix-members-frontend`.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Register a member

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';

/* Sample options value:
 * {
 *    contactInfo: {
 *      firstName: 'Javier',
 *      lastName: 'Doe',
 *      hobby: 'Basketball,
 *      "favorite-meal": 'Pasta'
 *    },
 *    privacyStatus: 'PUBLIC'
 * }
 */

export const myRegisterMemberFunction = webMethod(Permissions.Anyone, (email, password, options) => {
  return authentication.register(email, password, options)
    .then((registrationResult) => {
      return registrationResult;
    })
    .catch((error) => {
      console.error(error);
    })
});

/* Promise resolves to:
 * {
 *   "member": {
 *     "_id": "efaaf13f-934e-4449-b0c2-304030767671",
 *     "createdDate": "2021-08-01T12:28:42Z",
 *     "updatedDate": "2021-08-01T12:28:41.847Z",
 *     "status": "UNKNOWN",
 *     "contactId": "efaaf13f-934e-4449-b0c2-304030767671",
 *     "profile": {
 *       "nickname": "Javier Doe",
 *       "slug": "javierdoe"
 *     },
 *     "privacyStatus": "UNKNOWN",
 *     "activityStatus": "UNKNOWN"
 *   },
 *   "status": "PENDING",
 *   "approvalToken": "JWS.eyJraWQiOiJSc012MmV3MiIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImVmYWFmMTNmLTkzNGUtNDQ0OS1iMGMyLTMwNDAzMDc2NzY3MVwiLFwiY29sbGVjdGlvbklkXCI6XCI5YmVjNThlNi02NDExLTQ5OTEtOGU1ZC0wYWRhOTE4MmI5NWVcIn0iLCJpYXQiOjE2Mjc4MjA5MjEsImV4cCI6MTYyNzkyODkyMX0.zOuE8ZXRBQT4tPPFqvseE8xKm6kHrmHG3Lrndz7l7Ng"
 * }
 */
```

## Register a member using a 3rd party for approval

```javascript
/*******************************
 * Backend code - register.web.js *
 *******************************/
import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';
import { approveBy3rdParty } from 'backend/some-backend-module';

export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) => {

  // Call a 3rd-party API to check if the member is approved.
  const isApproved = await approveBy3rdParty(email, password);

  // If member is approved by 3rd party, register and approve with the Wix site
  if (isApproved === true) {
    const options = {
      contactInfo: {
        firstName: firstName,
        lastName: lastName
      }
    };

    // Register the member
    const registration = await authentication.register(email, password, options);
    const approvalToken = registration.approvalToken;
    console.log('Member is now registered with the site and pending approval');

    // Approve the member and get session token, to be used to log in the member client-side
    const sessionToken = await authentication.approveByToken(approvalToken);
    console.log('Member is now approved, but not logged in');

    return {
      approved: true,
      sessionToken: sessionToken
    };

  } else {
    // If not approved by the 3rd party

    await authentication.blockByEmail(email);
    console.log('Member not approved by 3rd-party SSO. Blocking from Wix site.');

    return { approved: false };
  }
});


/*************
 * Page code *
 *************/
import { authentication } from 'wix-members-frontend';
import { doRegistration } from 'backend/register.web';

// ...

$w('#register').onClick(() => {

  const email = $w('#email').value;
  const password = $w('#password').value;
  const firstName = $w('#firstName').value;
  const lastName = $w('#lastName').value;

  doRegistration(email, password, firstName, lastName)
    .then((result) => {
      if (result.approved) {
        // Log the member in
        console.log('Logging in...');
        authentication.applySessionToken(result.sessionToken);
      } else {
        console.log('Not approved!');
      }
    });
});
```

## Register a member, sending an email for confirmation

```javascript
/*******************************
 * Backend code - register.web.js *
 *******************************/

import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';
import { triggeredEmails } from 'wix-crm-backend';

export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) => {
  const registrationOptions = {
    contactInfo: {
      firstName: firstName,
      lastName: lastName
    }
  };
  const registration = await authentication.register(email, password, registrationOptions);
  console.log('Member is now registered with the site and pending approval');

  const emailOptions = {
    variables: {
      name: firstName,
      verifyLink: `http://yourdomain.com/post-register?token=${registration.approvalToken}`
    }
  };
  triggeredEmails.emailMember('verifyRegistration', registration.member.id, emailOptions);
  console.log('Confirmation email sent');
});

export const doApproval = webMethod(Permissions.Anyone, async (token) => {
  try {
    const sessionToken = await authentication.approveByToken(token);
    console.log('Member approved');
    return {
      approved: true,
      sessionToken: sessionToken
    };
  } catch (error) {
    console.log('Member not approved');
    return {
      approved: false,
      reason: error
    };
  }
});

/****************************
 * Page code - registration *
 ****************************/
import { doRegistration } from 'backend/register.web';

// ...

const email = $w('#email').value;
const password = $w('#password').value;
const firstName = $w('#firstName').value;
const lastName = $w('#lastName').value;

doRegistration(email, password, firstName, lastName)
  .then(() => {
    console.log('Confirmation email sent.');
  });

/*********************************
 * Page code - post-registration *
 *********************************/
import wixLocationFrontend from 'wix-location-frontend';
import { authentication } from 'wix-members-frontend';
import { doApproval } from 'backend/register.web';

$w.onReady(async () => {
  const token = wixLocationFrontend.query.token;

  const approval = await doApproval(token);

  if (approval.approved === true) {
    authentication.applySessionToken(approval.sessionToken);
    console.log('Member approved & logged in');
  } else {
    console.log('Member not approved');
  }
});

```

---