Hi everybody!
i just want to connect my database to my login website but is not working:
do i miss too connect my database som where?
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(‘#LoggIN’).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 Personnummer = $w(‘#PNummer’).value;
let Lösenord = $w(‘#Loord’).value;
wixUsers.login(Personnummer, Lösenord)
.then( () => {
console.log(“User is logged in”);
let baseUrl = wixLocation.baseUrl https://projectphoenix68.wixsite.com/mysite/Home; //Change the URL ending to whatever page you want to send the user to after they log in.
})
. catch ( (err) => {
console.log(err);
} );
}
What are you actually trying to achieve here, your own custom login/signup lightboxes?
First off, note that there are three types of login/signup of which you will want the Corvid option
https://support.wix.com/en/article/about-the-member-signup-form#corvid-form
Wix do a Corvid example for a form, which you can find here.
https://support.wix.com/en/article/corvid-tutorial-creating-a-custom-registration-form-with-code
Note, that if you do use Corvid for this, then you will need to change your member signup settings to suit your choice as shown here.
https://support.wix.com/en/article/corvid-enabling-custom-site-registration
If you want to have a members profile page, then this tutorial is a good option as it will let you make up a page that lets user login and logout and direct them to their member profile page.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area
Of course you can change this page to suit your needs and change the example to go to another page on your site.
However, note that if you direct your user to a new page after logging in then this example will work.
If you want the user to stay on the same page, then you will need to refresh the page after the user has logged themselves so that the page code will be worked again and make the members only parts of it change.
If you stay on the same page and don’t refresh the page after login, then the user will be logged in, however the button on the page will not change from login to logout and any member only elements set to be shown only when the member is logged in, will stay hidden to members.
Finally, there are other examples for login/signup through lightboxes and Corvid as shown here from Nayeli (Code Queen).
Wix Member Login - How to customize member login on Wix using Wix Code
https://www.totallycodable.com/wix/corvid/custom-registration-for-site-login-using-wix-code
Wix Custom Registration to Check Existing User and Input Validation
https://www.totallycodable.com/wix/corvid/corvid-registration-code-check-existing-user-and-input-validation
Nayeli has also done a tutorial for the Wix Members Profile tutorial that you may want to watch too.
2017 Create Member Profile Log In Page - Custom Private Client Member Dashboard - Wix Code
Updated version here.
Creating a client dashboard in Wix using Wix Code
https://codequeen.wixsite.com/membership-dashboard
thank u for replying:-) all that i know but! how i link my database in my script code.
instead of:
wixUser.login(email, password)
to
wixData.login(email, password)
Because in my website is no Sign up or registration form i want to add members in the database and thy just login?
You can’t use Wix Data API for site members to login.
https://www.wix.com/corvid/reference/wix-data.html
For site members to be able to login, then you need to be using Wix Users API.
https://www.wix.com/corvid/reference/wix-users.html
@givemeawhisky ok i understand if i want to do that i have to use mysql or phpmyadmin database if i want to but user i temple and connected to wix for login
But im just trying to link the login Lightbox to wix datebase. members whene the login its check with the database if the username and password is correct
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.
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
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.
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.
@givemeawhisky Thank you so much for your help! Im new to Wix and try t understand how things work here.
@givemeawhisky
If i use this code where the login data stored is in the code or wix have owne site there store the login (username and password) information. where from the lightbox or login page sync the information. it has to be database for users?
sorry for been annoying Im just trying to understand to build my own site.