Search...
loggedIn( )
Indicates whether the site visitor is a logged-in member.
Description
The loggedIn()
function returns a boolean value
indicating whether the current visitor is logged in as a site member.
If a member is logged in, loggedIn()
returns true
.
Otherwise, loggedIn()
returns false
.
Syntax
function loggedIn(): boolean
loggedIn Parameters
This function does not take any parameters.
Returns
true
if a member is logged in. Otherwise, false
.
Return Type:
boolean
Was this helpful?
Check whether a member is logged in
Copy Code
1import { authentication } from 'wix-members-frontend';23// ...45const isLoggedIn = authentication.loggedIn();67if (isLoggedIn) {8 console.log('Member is logged in');9} else {10 console.log('Member is not logged in');11}
Check for a logged-in member before getting member details
Copy Code
1import { authentication, currentMember } from 'wix-members-frontend';23$w.onReady(async () => {4 const isLoggedIn = authentication.loggedIn();56 if (isLoggedIn) {7 const loggedInMember = await currentMember.getMember()8 console.log('Member is logged in:', loggedInMember);9 const memberId = loggedInMember._id;10 const contactId = loggedInMember.contactId;11 } else {12 // Handle when member isn't logged in13 }14});
Show a logout button if a member is logged in
This code example runs on masterpage.js
and relies on a logout button,
which is hidden when the page loads.
When the page loads, if loggedIn()
returns true
,
the logout button is displayed.
Additionally, if a member logs in after the page loads,
the button is displayed in response to the login event.
Copy Code
1/*****************************2 * Page code - masterpage.js *3 ****************************/45import { authentication } from 'wix-members-frontend';67$w.onReady(function () {8 const loggedIn = authentication.loggedIn();910 if (loggedIn) {11 console.log('Logged in, showing the logout button');12 $w('#logout').show();13 }1415 authentication.onLogin(() => {16 console.log('Logged in, showing the logout button');17 $w('#logout').show();18 });19});20