Indicates whether the site visitor is a logged-in member.
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
.
function loggedIn(): Promise<boolean>;
import { authentication } from "@wix/site-members";
// ...
const isLoggedIn = await authentication.loggedIn();
if (isLoggedIn) {
console.log("Member is logged in");
} else {
console.log("Member is not logged in");
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Logs a registered member in with an email and password.
The login()
function returns a Promise that resolves when the member with
the specified email address and password is logged in.
The login()
function only works with existing members. To register a new member use
the register()
function.
Note:
wix-members-frontend
are only partially functional when previewing your site.
View a published version of your site to see their complete functionality.function login(email: string, password: string): Promise<void>;
Login email address.
Member password.
import { authentication } from "@wix/site-members";
// ...
authentication
.login(email, password)
.then(() => {
console.log("Member is logged in");
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Logs the current member out of the site.
The logout()
function logs the current member out of the site.
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.
function logout(): Promise<void>;
import { authentication } from "@wix/site-members";
// ...
authentication.logout();
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Sets the function that runs when a member logs in.
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.
function onLogin(handler: function): Promise<void>;
handler(currentMember: CurrentMember): void
Function name or expression to run when a member logs in.
import { authentication } from "@wix/site-members";
// ...
authentication.onLogin(async (member) => {
const loggedInMember = await member.getMember();
const memberId = loggedInMember._id;
console.log(`Member ${memberId} logged in:`, loggedInMember);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Sets the function that runs when a member logs out.
Use the onLogout()
function for code you want to run after a member logs out
from your site.
Usually, you want to call the onLogout()
function in the masterPage.js file in the
code editor so that the onLogout()
event handler runs no matter which
page on your site a member uses to log out.
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.
function onLogout(handler: function): Promise<void>;
handler(): void
Function name or expression to run when a member logs out.
import { authentication } from "@wix/site-members";
// ...
authentication.onLogout(() => {
console.log("Member logged out");
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Prompts the current site visitor with a password reset modal.
The promptForgotPassword()
function returns a Promise that resolves when
the visitor submits the Create New Password form.
If the visitor cancels the form without submitting it, the Promise is rejected.
promptForgotPassword()
cannot be called before the page is ready.
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.
If you return
or await
the promptForgotPassword()
function
when calling from onReady()
, the page will be prevented from loading.
To handle the resolved promise, use .then()
and .catch()
.
function promptForgotPassword(): Promise<void>;
import { authentication } from "@wix/site-members";
// ...
authentication
.promptForgotPassword()
.then(() => {
console.log('Sending "forgot password" email');
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Prompts the current visitor to log in as a site member.
The promptLogin()
function returns a Promise that resolves
when the login has completed.
If the visitor cancels the form without logging in, the Promise is rejected.
The promptLogin()
function cannot be called before the page is ready.
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.
If you return
or await
the promptLogin()
function
when calling from onReady()
, the page will be prevented from loading.
To handle the resolved promise, use .then()
and .catch()
.
function promptLogin(options: LoginOptions): Promise<void>;
The options that determine how the login dialog box appears.
import { authentication } from "@wix/site-members";
// ...
// Sample options value:
// {
// mode: 'login',
// modal: true
// }
authentication
.promptLogin(options)
.then(() => {
console.log("Member is logged in");
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Registers a new site member.
The register()
function returns a Promise that resolves to a RegistrationResult
object when the member is registered or pending registration.
The specified password
must be between 4 and 100 ASCII characters.
See New Members to learn about verifying emails and approving members.
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 member data in the resolved Promise includes custom fields from your site's contacts only if they are added to your site members in your dashboard.
When a new member signs up using an email address
that's already in your site's Contact List,
a notification is displayed
and a confirmation email is sent to the new member.
To register a member without displaying the notification, use
register()
from wix-members-backend
(this does not suppress the confirmation email).
When your site's member signup settings are set to automatic approval,
calling register()
from wix-members-frontend
(in page code) is as secure as calling
register()
from wix-members-backend (in backend code),
unless you are implementing custom site registration using Velo forms.
However, when registration is set to manual approval,
calling register()
from wix-members-backend
allows you to build more secure approval flows
by keeping tokens hidden from the frontend.
function register(
email: string,
password: string,
options: RegistrationOptions,
): Promise<RegistrationResult>;
Email address the new member will use to log in.
Password to assign to the new member. Must be 4 to 100 ASCII characters.
Registration options.
This example contains a custom field, "Hobby".
import { authentication } from "@wix/site-members";
// ...
/* Sample options value:
* {
* contactInfo: {
* firstName: 'Juan',
* lastName: 'Doe',
* picture: 'https://static.parastorage.com/unpkg-semver/communities-blog-statics/assets/wix-logo.png',
* hobby: 'Football'
* },
* privacyStatus: "PRIVATE"
* }
*/
authentication
.register(email, password, options)
.then((registrationResult) => {
const status = registrationResult.status;
if (status === "PENDING") {
// When the site is configured for manual approval,
// status is "PENDING" and approvalToken is returned.
const approvalToken = registrationResult.approvalToken;
console.log(
"Member registered and waiting for approval:",
registrationResult,
);
} else {
// When the site is configured for automatic approval,
// status is "ACTIVE" and the member is approved and logged in.
// To prevent logging in the member automatically,
// use the backend function: wix-members-backend.authentication.register()
console.log("Member registered and logged in:", registrationResult);
}
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Resends a one-time password (OTP) for email verification.
Important:
This function is in Developer Preview and is subject to change.
The resendVerificationCodeEmail()
function returns a Promise that resolves when the email is successfully sent, or rejects with an error if the operation fails.
function resendVerificationCodeEmail(): Promise<void>;
import { authentication } from "@wix/site-members";
authentication
.resendVerificationCodeEmail()
.then(() => {
console.log("Verification code email resent");
})
.catch((error) => {
console.error("Error resending verification email:", error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.