For Wix Corvid Login Lightbox, you just need to do something like this.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
$w("#forgotPassword").onClick( (event) => {
//wixWindow.lightbox.close()
wixUsers.promptForgotPassword()
.then( ( ) => {
//
} )
.catch( (err) => {
let errorMsg = err; //"The user closed the forgot password dialog"
});
});
});
export function loginButton_click(event) {
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
wixLocation.to("/account/my-account"); //Change the URL ending to whatever page you want to send the user to after they log in.
} )
.catch( (err) => {
console.log(err);
$w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} );
}
Or if you are wanting to stay on the same page.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
$w("#forgotPassword").onClick( (event) => {
//wixWindow.lightbox.close()
wixUsers.promptForgotPassword()
.then( ( ) => {
//
} )
.catch( (err) => {
let errorMsg = err; //"The user closed the forgot password dialog"
});
});
});
export function loginButton_onclick(event) {
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
wixWindow.lightbox.close();
wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts.
} )
.catch( (err) => {
console.log(err);
$w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} );
}
If you are wanting to send your users to an external website page after the user has logged in, then have a look at Wix Location and the to function here.
https://www.wix.com/corvid/reference/wix-location.html#to
http(s)://: An external web address.
Navigate to an external web link
import wixLocation from 'wix-location';
// ...
wixLocation.to("http://wix.com");
Also, note with this line of code…
let baseUrl = wixLocation.baseUrl https://projectphoenix68.wixsite.com/mysite/Home
You are just getting the base URL of the page
https://www.wix.com/corvid/reference/wix-location.html#baseUrl
baseUrl
Gets the base URL of the current page.
If the site is not yet published, the function returns null.
Examples
Get the base URL of the current page
import wixLocation from 'wix-location';
// ...
let baseUrl = wixLocation.baseUrl;
// Premium site: "https://domain.com/"
// Free site: "https://user.wix-sites.com/zoo/"
You can read more about baseURL here.
https://support.wix.com/en/article/corvid-about-the-url-structure-of-premium-and-free-sites#base-url
Wix Users API needs to be tested on a fully published website and not tested just through the Wix Preview.
https://www.wix.com/corvid/reference/wix-users.html
The APIs in wix-users are only partially functional when previewing your site.
View a published version of your site to see their complete functionality.