import type { RegistrationOptions } from "./types.js"; /** * Registers a new site member. * * After registration, the member's status is either `PENDING` (which requires email verification or admin approval) * or `ACTIVE` (member is immediately logged in). The status depends on your [site's member signup settings](https://support.wix.com/en/article/site-members-managing-signup-login-and-security-settings-for-your-site-members). * * @param email - The email address for the new member account. * @param password - The password for the new member account. * @param options - Registration options including contact information and privacy status. * * @requiredField email * @requiredField password * * @returns A promise that resolves with the registration result containing the member's status. * * @example Register a new member with email and password * ```typescript * import { authentication } from '@wix/site'; * * try { * const result = await authentication.register('user@example.com', 'securePassword123'); * * if (result.status === 'ACTIVE') { * console.log('Member registered and logged in'); * } else if (result.status === 'PENDING') { * console.log('Member registered, awaiting approval or email verification'); * } * } catch (error) { * console.error('Registration failed:', error); * } * ``` * * @example Register a new member with additional contact information * ```typescript * import { authentication } from '@wix/site'; * * const options = { * contactInfo: { * firstName: 'John', * lastName: 'Doe', * picture: 'https://example.com/photo.jpg', * emails: ['john.doe@example.com'], * phones: ['+1234567890'], * language: 'en', * customFields: { * company: 'Acme Inc', * }, * }, * privacyStatus: 'PUBLIC', * }; * * const result = await authentication.register('john.doe@example.com', 'securePassword123', options); * console.log('Registration status:', result.status); * ``` */ export declare function register(email: string, password: string, options?: RegistrationOptions): Promise; /** * Logs in a registered member with the provided email and password. * * Upon successful login, the member's session is established and they gain access to member-only content and features. * * @param email - Member's email address. * @param password - Member's password. * * @requiredField email * @requiredField password * * @returns A promise that resolves when login is successful. * * @throws Error if the email or password is invalid, or if the member account requires a password reset. * * @example Log in a member * ```typescript * import { authentication } from '@wix/site'; * * try { * await authentication.login('user@example.com', 'password123'); * console.log('Login successful'); * } catch (error) { * console.error('Login failed:', error); * } * ``` * * @example Log in with error handling for specific cases * ```typescript * import { authentication } from '@wix/site'; * * try { * await authentication.login('user@example.com', 'password123'); * // Redirect to member area or refresh page * window.location.href = '/members-area'; * } catch (error) { * if (error.code === 'invalidPassword') { * console.error('Incorrect password'); * } else if (error.code === 'resetPassword') { * console.error('Password reset required'); * } else { * console.error('Login failed:', error); * } * } * ``` */ export declare function login(email: string, password: string): Promise; /** * Logs out the current member from the site. * * @returns A promise that resolves when logout is complete. * * @example Log out the current member * ```typescript * import { authentication } from '@wix/site'; * * try { * await authentication.logout(); * console.log('Logout successful'); * // Redirect to home page or login page * window.location.href = '/'; * } catch (error) { * console.error('Logout failed:', error); * } * ``` * * @example Log out with a confirmation dialog * ```typescript * import { authentication } from '@wix/site'; * * async function handleLogoutClick() { * if (!authentication.loggedIn()) { * console.log('No member is currently logged in'); * return; * } * * const confirmed = window.confirm('Are you sure you want to log out?'); * if (confirmed) { * await authentication.logout(); * window.location.reload(); * } * } * ``` */ export declare function logout(): Promise; /** * Applies a session token to establish a member session. * * This function authenticates a member using a session token. The token is usually obtained from [Register](https://dev.wix.com/docs/sdk/host-modules/site/authentication/register), [Login](https://dev.wix.com/docs/sdk/host-modules/site/authentication/login) methods, * or a 3rd-party authentication provider. After applying the token, the member is logged in and has access to member-only content. * * @param token - Session token to apply. * * @requiredField token * * @returns A promise that resolves when the session token is applied successfully. * * @example Apply a session token received from the backend * ```typescript * import { authentication } from '@wix/site'; * * // Token received from your backend authentication flow * const sessionToken = 'your-session-token-from-backend'; * * try { * await authentication.applySessionToken(sessionToken); * console.log('Session established successfully'); * } catch (error) { * console.error('Failed to apply session token:', error); * } * ``` * * @example Apply a session token from a custom OAuth flow * ```typescript * import { authentication } from '@wix/site'; * * async function handleOAuthCallback(tokenFromOAuth: string) { * try { * await authentication.applySessionToken(tokenFromOAuth); * * if (authentication.loggedIn()) { * console.log('OAuth login successful'); * // Redirect to member dashboard * window.location.href = '/dashboard'; * } * } catch (error) { * console.error('OAuth login failed:', error); * } * } * ``` */ export declare function applySessionToken(token: string): Promise; /** * Checks if a member is currently logged in to the site. * * Use this function to determine the current authentication state and to show or hide content based on login status. * * @returns `true` if a member is currently logged in, `false` otherwise. * * @example Check if a member is logged in * ```typescript * import { authentication } from '@wix/site'; * * if (authentication.loggedIn()) { * console.log('Member is logged in'); * // Show member-only content * } else { * console.log('No member is logged in'); * // Show login prompt * } * ``` * * @example Conditionally render UI based on login status * ```typescript * import { authentication } from '@wix/site'; * * function renderAuthButton() { * const button = document.getElementById('authButton'); * * if (authentication.loggedIn()) { * button.textContent = 'Logout'; * button.onclick = () => authentication.logout(); * } else { * button.textContent = 'Login'; * button.onclick = () => { * // Show login form * }; * } * } * ``` */ export declare function loggedIn(): boolean; /** * Registers a callback function to be called when a member logs in. * * Use this function to run code after a member successfully logs in, such as updating the UI, loading member-specific data, * or tracking login events. * * @param handler - Callback function to run when a member logs in. * * @requiredField handler * * @returns A function that removes the event listener when called. * * @example Subscribe to login events * ```typescript * import { authentication } from '@wix/site'; * * const unsubscribe = authentication.onLogin(() => { * console.log('Member logged in'); * // Update UI to show member content * document.getElementById('memberGreeting').style.display = 'block'; * }); * * // Later, to stop listening: * // unsubscribe(); * ``` * * @example Track login events and clean up on component unmount * ```typescript * import { authentication } from '@wix/site'; * * function initAuthTracking() { * const unsubscribeLogin = authentication.onLogin(() => { * console.log('Login event tracked'); * // Send analytics event * }); * * const unsubscribeLogout = authentication.onLogout(() => { * console.log('Logout event tracked'); * // Send analytics event * }); * * // Return cleanup function * return () => { * unsubscribeLogin(); * unsubscribeLogout(); * }; * } * ``` */ export declare function onLogin(handler: () => void): import("@wix/sdk-runtime/cjs/build/nanoevents.js").Unsubscribe; /** * Registers a callback function to be called when a member logs out. * * Use this function to run code after a member logs out, such as clearing cached data, updating the UI, * or redirecting to a public page. * * @param handler - Callback function to run when a member logs out. * * @requiredField handler * * @returns A function that removes the event listener when called. * * @example Subscribe to logout events * ```typescript * import { authentication } from '@wix/site'; * * const unsubscribe = authentication.onLogout(() => { * console.log('Member logged out'); * // Clear any cached member data * localStorage.removeItem('memberPreferences'); * // Redirect to home page * window.location.href = '/'; * }); * * // Later, to stop listening: * // unsubscribe(); * ``` * * @example Handle logout with UI updates * ```typescript * import { authentication } from '@wix/site'; * * function setupLogoutHandler() { * const unsubscribe = authentication.onLogout(() => { * // Hide member-only content * document.querySelectorAll('.member-only').forEach(el => { * el.style.display = 'none'; * }); * * // Show login prompt * document.getElementById('loginPrompt').style.display = 'block'; * }); * * return unsubscribe; * } * ``` */ export declare function onLogout(handler: () => void): import("@wix/sdk-runtime/cjs/build/nanoevents.js").Unsubscribe; /** * Sends a password reset email to a member. * * After sending the email, the member can click the link to reset their password. In headless environments the member is redirected * to the provided `redirectUri` after resetting. In the Velo environment, the `redirectUri` parameter is ignored. * * @param email - Login email of the member whose password will be reset. * @param redirectUri - The URI to redirect to after the password is reset. Used only in headless environments. In the Velo environment, this parameter is ignored. * * @requiredField email * @requiredField redirectUri * * @returns A promise that resolves when the password reset email is sent. * * @example Send a password reset email * ```typescript * import { authentication } from '@wix/site'; * * try { * await authentication.sendPasswordResetEmail('user@example.com', 'https://example.com/reset-callback'); * console.log('Password reset email sent'); * } catch (error) { * console.error('Failed to send password reset email:', error); * } * ``` * * @example Send a password reset email with a login page redirect * ```typescript * import { authentication } from '@wix/site'; * * async function handleForgotPassword(email: string) { * try { * await authentication.sendPasswordResetEmail(email, 'https://example.com/login'); * console.log('Check your email for a password reset link'); * } catch (error) { * console.error('Failed to send password reset email:', error); * } * } * ``` */ export declare function sendPasswordResetEmail(email: string, redirectUri: string): Promise; /** * Returns the login URL for sites that use Wix as their identity provider. * * Use this function when your site uses a [Wix login page](https://dev.wix.com/docs/go-headless/develop-your-project/self-managed-headless/authentication/members/wix-login-page/about-wix-login-pages) * to handle member authentication. Wix manages the login experience and redirects the member back to your site after authentication. * The returned URL points to the `/api/auth/login` route. * * @param returnToUrl - The URL to redirect to after login. * * @requiredField returnToUrl * * @returns The Wix-managed login URL with the `returnToUrl` query parameter. * * @example Redirect to the Wix login page * ```typescript * import { authentication } from '@wix/site'; * * const loginUrl = authentication.getWixManagedLoginUrl('https://example.com/members-area'); * window.location.href = loginUrl; * ``` * * @example Use with a login button * ```typescript * import { authentication } from '@wix/site'; * * function setupLoginButton() { * const button = document.getElementById('loginButton'); * button.onclick = () => { * window.location.href = authentication.getWixManagedLoginUrl(window.location.href); * }; * } * ``` */ export declare function getWixManagedLoginUrl(returnToUrl: string): string; /** * Returns the logout URL for sites that use Wix as their identity provider. * * Use this function when your site uses a [Wix login page](https://dev.wix.com/docs/go-headless/develop-your-project/self-managed-headless/authentication/members/wix-login-page/about-wix-login-pages) * to handle member authentication. Wix manages the logout flow and redirects the member back to your site afterward. * The returned URL points to the `/api/auth/logout` route. * * @param returnToUrl - The URL to redirect to after logout. * * @requiredField returnToUrl * * @returns The Wix-managed logout URL with the `returnToUrl` query parameter. * * @example Redirect to the Wix logout page * ```typescript * import { authentication } from '@wix/site'; * * const logoutUrl = authentication.getWixManagedLogoutUrl('https://example.com/'); * window.location.href = logoutUrl; * ``` * * @example Use with a logout button * ```typescript * import { authentication } from '@wix/site'; * * function setupLogoutButton() { * const button = document.getElementById('logoutButton'); * button.onclick = () => { * window.location.href = authentication.getWixManagedLogoutUrl('/'); * }; * } * ``` */ export declare function getWixManagedLogoutUrl(returnToUrl: string): string; //# sourceMappingURL=authentication.d.ts.map