Logs the current member into the site using the given session token.
The applySessionToken()
function returns a Promise that resolves when the
given session token is applied and the current member is logged into the site.
You receive a session token from the following wix-members-backend functions:
Pass the returned session token to your page code and apply it by
calling applySessionToken()
to complete the process started by one of the
above functions.
function applySessionToken(sessionToken: string): Promise<void>;
Session token to apply.
import { authentication } from "wix-members-frontend";
// ...
authentication.applySessionToken(sessionToken).then(() => {
console.log("Member logged in.");
});
Changes the member's password to a new one, using a reset token.
Important:
This function is in Developer Preview and is subject to change.
The changePassword()
function returns a Promise that resolves
when the password is successfully changed, or rejects with an error if the operation fails.
function changePassword(newPassword: string, token: string): Promise<void>;
New password the member wants to set. Minimum 6 characters.
Reset token received in the email triggered by the sendResetPasswordEmail() function.
import { authentication } from "wix-members-frontend";
authentication
.changePassword(newPassword, token)
.then(() => {
console.log("Password changed successfully");
})
.catch((error) => {
console.error("Error changing password:", error);
});
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(): boolean;
import { authentication } from "wix-members-frontend";
// ...
const isLoggedIn = authentication.loggedIn();
if (isLoggedIn) {
console.log("Member is logged in");
} else {
console.log("Member is not logged in");
}
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-members-frontend";
// ...
authentication
.login(email, password)
.then(() => {
console.log("Member is logged in");
})
.catch((error) => {
console.error(error);
});
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(): void;
import { authentication } from "wix-members-frontend";
// ...
authentication.logout();
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): void;
handler(currentMember: CurrentMember): void
Function name or expression to run when a member logs in.
import { authentication } from "wix-members-frontend";
// ...
authentication.onLogin(async (member) => {
const loggedInMember = await member.getMember();
const memberId = loggedInMember._id;
console.log(`Member ${memberId} logged in:`, loggedInMember);
});