approveByToken( )


Approves a pending member using an approval token.

The approveByToken() function returns a Promise that resolves to a session token when the specified member is approved. Tokens must be approved within 30 hours of token creation.

A new member's status is "PENDING" when the site's membership policy is set to manual approval. To learn more about setting your site's membership approval policy, see Editing Your Member Signup Settings.

Use the approvalToken parameter returned from the register() function when calling approveByToken().

Method Declaration
Copy
function approveByToken(token: string): Promise<string>;
Method Parameters
tokenstringRequired

Approval token returned by the register() function.

Returns
Return Type:Promise<string>

This example contains a backend function that approves a pending member using an approval token. It returns a session token to be used in page code to log in the member who was just approved.

JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { authentication } from "wix-members-backend"; // Sample token value: // 'JWS.eyJraWQiOiJSc012MmV3MiIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImEyMWE1MmU4LWViMzUtNDExYS04OTNkLWFlNTgxM2I1YjY2Y1wiLFwiY29sbGVjdGlvbklkXCI6XCI5YmVjNThlNi02NDExLTQ5OTEtOGU1ZC0wYWRhOTE4MmI5NWVcIn0iLCJpYXQiOjE2Mjc3NzkyNjYsImV4cCI6MTYyNzg4NzI2Nn0.53pZSaPInXrAvWpTOxsZxqxBHQIof1j6Gbkqg92l82o' export const myApproveByTokenFunction = webMethod( Permissions.Anyone, (token) => { return authentication .approveByToken(token) .then((sessionToken) => { return { sessionToken: sessionToken, approved: true, }; }) .catch((error) => { return { approved: false, reason: error, }; }); }, ); /* Promise resolves to: * "JWS.eyJraWQiOiJQSXpvZGJiQiIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1wiaWRcIjpcImEyMWE1MmU4LWViMzUtNDExYS04OTNkLWFlNTgxM2I1YjY2Y1wiLFwiY29sbGVjdGlvbklkXCI6XCI5YmVjNThlNi02NDExLTQ5OTEtOGU1ZC0wYWRhOTE4MmI5NWVcIixcIm1ldGFTaXRlSWRcIjpcIjFmZjQ2YTk2LWRlYTYtNDlkYS04M2JhLTUxNjRmYjYyZDgzOVwiLFwib3duZXJcIjpmYWxzZSxcImNyZWF0aW9uVGltZVwiOjE2Mjc3Nzk0MTg5NzUsXCJleHBpcmVzSW5cIjoxMjA5NjAwMDAwLFwiZXhwaXJhdGlvblRpbWVcIjoxNjI3Nzc5NTM4OTc1LFwibGFzdFJlZnJlc2hlZFwiOjAsXCJhZG1pblwiOmZhbHNlfSIsImlhdCI6MTYyNzc3OTQxOH0.srXs33K5gT5KaZp4fTZ9xRkVasayOTox6IK2ZG3tKrA" */
Errors

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

Did this help?