generateSessionToken( )


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 Declaration
Copy
function generateSessionToken(email: string): Promise<string>;
Method Parameters
emailstringRequired

Login email address of the member to approve.

Returns
Return Type:Promise<string>
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" */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?