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): voidhandler: function LoginHandler(currentMember: CurrentMember): void
onLogin Parameters
NAME
TYPE
DESCRIPTION
Returns
This function does not return anything.
Return Type:
LoginHandler Parameters
NAME
TYPE
DESCRIPTION
Returns
This function does not return anything.
Return Type:
Was this helpful?
Run code when a member logs in
1import {authentication} from 'wix-members-frontend';23// ...45authentication.onLogin(async (member) => {6 const loggedInMember = await member.getMember();7 const memberId = loggedInMember._id;8 console.log(`Member ${memberId} logged in:`, loggedInMember);9});