> 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: generateSessionToken(email: string)

# Method package: wixMembersBackend

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

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

# Method Description:

Creates a session token for a member authenticated by a 3rd party.


The `generateSessionToken()` function returns a Promise that resolves to a session token
used to log a member in to your site.

Use `generateSessionToken()` to bypass Wix member authentication
when using a 3rd-party service to authenticate your members.
For example, you can use `generateSessionToken()`
to provide Single Sign-On (SSO) for members
where they authenticate with a non-Wix entity to log in to your Wix site.

If the specified email address corresponds to an existing member,
a session token for logging in that member is generated.

If there is no existing member with the specified email address,
a new member is created and a session token for logging in that member is generated.
The member is created with a random password.



# Method Code Examples:

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

## Generate a session token

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

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

/* Promise resolves to a session token:
 * "JWS.eyJraWQiOiJQSXpvZGJiQiIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImM2OTE2N2FmLTY0ODgtNDYzNS1iYmU3LTg5YzFjZWY2MTEwN1wiLFwiY29sbGVjdGlvbklkXCI6XCI5YmVjNThlNi02NDExLTQ5OTEtOGU1ZC0wYWRhOTE4MmI5NWVcIixcIm1ldGFTaXRlSWRcIjpcIjFmZjQ2YTk2LWRlYTYtNDlkYS04M2JhLTUxNjRmYjYyZDgzOVwiLFwib3duZXJcIjpmYWxzZSxcImNyZWF0aW9uVGltZVwiOjE2MjI0MDMwOTM5MTEsXCJleHBpcmVzSW5cIjoxMjA5NjAwMDAwLFwiZXhwaXJhdGlvblRpbWVcIjoxNjIyNDAzMjEzOTExLFwibGFzdFJlZnJlc2hlZFwiOjAsXCJhZG1pblwiOmZhbHNlfSIsImlhdCI6MTYyMjQwMzA5M30.xDMCeRG2DIDa4YR6_XuTf7KBRgHFb0qW7K6gsVMLXUM"
 */
```

## Log a member in after 3rd-party authentication

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

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

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

  return authBy3rdParty(email, password)
    .then((isAuthenticated) => {

      // If authenticated, generate and return the session token
      if (isAuthenticated) {
        return authentication.generateSessionToken(email)
          .then((sessionToken) => {
            return {
              sessionToken: sessionToken,
              approved: true
            };
          });
      }

      // If not authenticated, return non-approval
      return { approved: false };
    });
});

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

// ...

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

// Call the backend function to get the session token
getLoginToken(email, password)
  .then((loginResult) => {
    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.log("Member not approved.");
    }
  });
```

---