Search.../

onLogin( )

Sets the function that runs when a member logs in.

Description

The onLogin() event handler runs when a member logs into your site.

onLogin receives a currentMember object for the logged-in member, which contains the CurrentMember methods you can use to retrieve the member's information.

Usually, you want to call onLogin() in the masterPage.js file in the code editor so that the onLogin() event handler runs no matter which page a member uses to log in.

Notes:

  • The APIs in wix-members-frontend are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

  • The APIs in wix-members-frontend can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.

Syntax

function onLogin(handler: LoginHandler): void
handler: function LoginHandler(currentMember: CurrentMember): void

onLogin Parameters

NAME
TYPE
DESCRIPTION
handler

Function name or expression to run when a member logs in.

Returns

This function does not return anything.

Return Type:

void

LoginHandler Parameters

NAME
TYPE
DESCRIPTION
currentMember

Logged-in member.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Run code when a member logs in

Copy Code
1import {authentication} from 'wix-members-frontend';
2
3// ...
4
5authentication.onLogin(async (member) => {
6 const loggedInMember = await member.getMember();
7 const memberId = loggedInMember._id;
8 console.log(`Member ${memberId} logged in:`, loggedInMember);
9});