> 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: approveByToken(token: string) # Method package: wixMembersBackend # Method menu location: wixMembersBackend --> Authentication --> approveByToken # Method Link: https://dev.wix.com/docs/velo/apis/wix-members-backend/authentication/approve-by-token.md # Method Description: 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](https://support.wix.com/en/article/editing-your-member-signup-settings-for-the-default-form). Use the `approvalToken` parameter returned from the [`register()`](wix-members-backend/authentication/register) function when calling `approveByToken()`. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Approve a pending member using an approval token ```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" */ ``` ## Register a member using a 3rd party for approval ```javascript /******************************* * Backend code - register.web.js * *******************************/ import { Permissions, webMethod } from 'wix-web-module'; import { authentication } from 'wix-members-backend'; import { approveBy3rdParty } from 'backend/some-backend-module'; export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) => { // Call a 3rd-party API to check if the member is approved. const isApproved = await approveBy3rdParty(email, password); // If member is approved by 3rd party, register and approve with the Wix site if (isApproved === true) { const options = { contactInfo: { firstName: firstName, lastName: lastName } }; // Register the member const registration = await authentication.register(email, password, options); const approvalToken = registration.approvalToken; console.log('Member is now registered with the site and pending approval'); // Approve the member and get session token, to be used to log in the member client-side const sessionToken = await authentication.approveByToken(approvalToken); console.log('Member is now approved, but not logged in'); return { approved: true, sessionToken: sessionToken }; } else { // If not approved by the 3rd party await authentication.blockByEmail(email); console.log('Member not approved by 3rd-party SSO. Blocking from Wix site.'); return { approved: false }; } }); /************* * Page code * *************/ import { authentication } from 'wix-members-frontend'; import { doRegistration } from 'backend/register.web'; // ... $w('#register').onClick(() => { const email = $w('#email').value; const password = $w('#password').value; const firstName = $w('#firstName').value; const lastName = $w('#lastName').value; doRegistration(email, password, firstName, lastName) .then((result) => { if (result.approved) { // Log the member in console.log('Logging in...'); authentication.applySessionToken(result.sessionToken); } else { console.log('Not approved!'); } }); }); ``` ## Register a user sending an email for confirmation ```javascript /******************************* * Backend code - register.web.js * *******************************/ import { Permissions, webMethod } from 'wix-web-module'; import { authentication } from 'wix-members-backend'; import { triggeredEmails } from 'wix-crm-backend'; export const doRegistration = webMethod(Permissions.Anyone, async (email, password, firstName, lastName) => { const registrationOptions = { contactInfo: { firstName: firstName, lastName: lastName } }; const registration = await authentication.register(email, password, registrationOptions); console.log('Member is now registered with the site and pending approval'); const emailOptions = { variables: { name: firstName, verifyLink: `http://yourdomain.com/post-register?token=${registration.approvalToken}` } }; triggeredEmails.emailMember('verifyRegistration', registration.member.id, emailOptions); console.log('Confirmation email sent'); }); export const doApproval = webMethod(Permissions.Anyone, async (token) => { try { const sessionToken = await authentication.approveByToken(token); console.log('Member approved'); return { approved: true, sessionToken: sessionToken }; } catch (error) { console.log('Member not approved'); return { approved: false, reason: error }; } }); /**************************** * Page code - registration * ****************************/ import { doRegistration } from 'backend/register.web'; // ... const email = $w('#email').value; const password = $w('#password').value; const firstName = $w('#firstName').value; const lastName = $w('#lastName').value; doRegistration(email, password, firstName, lastName) .then(() => { console.log('Confirmation email sent.'); }); /********************************* * Page code - post-registration * *********************************/ import wixLocationFrontend from 'wix-location-frontend'; import { authentication } from 'wix-members-frontend'; import { doApproval } from 'backend/register.web'; $w.onReady(async () => { const token = wixLocationFrontend.query.token; const approval = await doApproval(token); if (approval.approved === true) { authentication.applySessionToken(approval.sessionToken); console.log('Member approved & logged in'); } else { console.log('Member not approved'); } }); ``` ---