> 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`). > - 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."); } }); ``` ---