> 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: login(email: string, password: string)

# Method package: wixMembersBackend

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

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

# Method Description:

Logs a registered member in with an email and password.


The `login()` function returns a Promise that resolves to a session token
used to log a member in to your site.

The `login()` function only works with existing members. To register a new member use 
the [`register()` function](#register).

To complete the login,
the returned session token must be applied using the
[`applySessionToken()`](https://dev.wix.com/docs/velo/api-reference/wix-members-frontend/authentication/apply-session-token.md)
function (from wix-members-frontend) in page code.



# Method Code Examples:

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

## Generate a session token if a valid email and password are provided

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

export const myLoginFunction = webMethod(Permissions.Anyone, (email, password) => {
  return authentication.login(email, password)
    .then((sessionToken) => {
      return sessionToken;
    })
    .catch((error) => {
      console.error(error);
    });
});

/* Promise resolves to a session token:
 * "JWS.eyJraWQiOiJQSXpvZGJiQiIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcIjg4MzFlZWQ2LTkyOGUtNGY4NS1iODBhLWUxZTQ4ZmI3YzRmZFwiLFwiY29sbGVjdGlvbklkXCI6XCI5YmVjNThlNi02NDExLTQ5OTEtOGU1ZC0wYWRhOTE4MmI5NWVcIixcIm1ldGFTaXRlSWRcIjpcIjFmZjQ2YTk2LWRlYTYtNDlkYS04M2JhLTUxNjRmYjYyZDgzOVwiLFwib3duZXJcIjpmYWxzZSxcImNyZWF0aW9uVGltZVwiOjE2MjI0MTUxMTMyNjYsXCJleHBpcmVzSW5cIjoxMjA5NjAwMDAwLFwiZXhwaXJhdGlvblRpbWVcIjoxNjIyNDE1MjMzMjY2LFwibGFzdFJlZnJlc2hlZFwiOjAsXCJhZG1pblwiOmZhbHNlfSIsImlhdCI6MTYyMjQxNTExM30.CFJTkyDaF6LypH8UuNm74qgZMxTKFgB1ZnzsemhY_KY"
 */
```

## Log a member in after they provide an email and password

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

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

export const getLoginToken = webMethod(Permissions.Anyone, async (email, password) => {

  let sessionToken;

  try {
    sessionToken = await authentication.login(email, password);

    // If the promise resolves, the member is authenticated and can be logged in
    return {
      sessionToken: sessionToken,
      approved: true
    };
  } catch (error) {
    // If the promise is rejected, the member is not authenticated
    // and cannot be logged in
    console.error(error);
    return {
      approved: false,
      error: error
    };
  }
});

/*************
* Page code *
************/

import { getLoginToken } from 'backend/login.web';
import { authentication } from 'wix-members-frontend';

$w('#login').onClick(async () => {
  const email = $w('#email').value;
  const password = $w('#password').value

  // Call the backend function to get the session token
  const loginResult = await getLoginToken(email, password);

  if (loginResult.approved) {
    // If approved, log the member in using the returned session token
    authentication.applySessionToken(loginResult.sessionToken);
  } else {
    // If not approved, log a message
    console.error('Login not approved.');
  }
});
```

---