Members only login area/database

HI guys i,m new to this so now here is were I really need your help, I want to create a log in / sign up / sign out button on all pages which takes you to a log in / sign up page. If you
want to sign up it should take you to a page created so you
can create an account with log in details and password, I must be able to approve or reject your application. If you already have an account you enter your login details and password and these are checked via the database and if correct allow you into the members only section. I also need the members
details to be visible to them from the database when they log in, none of this currently exists on my site hope I got all this correct ??

HI Guys
Any one got any ideas on how to do this, all help greatfuly recieved .

have you tried this?

HI al learning, this looks very interesting and might be the answer to what I was looking for.
Many thanks for your help.
Dave

Yes, I am trying to do the same. You don’t actual need wix code to create the members only login/sign up pages. However, I do want all the sign up details to appear in my database collection. Basically, once people “sign up” and become a member it should give them access to a page with a form where they submit details and upload a photo etc Do these sync up? Can my members details be linked to a database? Let me know if I should rephrase…

Hi Ashley.

Please look at Page Not Found - Velo API Reference - Wix.com and https://www.wix.com/code/reference/wix-data.html.
I think with the combination of those you might achieve what you are looking for.

Regards,
Genry.

1 Like

I was able to achieve with no code. created paid membership job group created landing page [subscription service) when payment is sucessful I have members redirected to my job board using forum. zi have opted to manual control membership approval. theres an option FOR this they will have to login and create accounf to gain access to board

and make sure everything in forum is set to members only

HI Guys
Well I finally got round to creating a members only log in page with links to a database.
I saw Michael Strauch’s video on doing it Create A Member Profile Log In Page - Custom Client or Member Dashboard - Wix Code Tutorial - YouTube and copied it to the letter.
Everything looked good, I uploaded it to test it on my live site and when I press the log in button nothing happens !!??
Has anyone had the same problem and know what the answer is ???
Also can some one tell me how to delete a database from my site as I can’t find a way of doing it ?
As you can probably guess I don’t have a clue about using wix code so somebody please help me before I completely lose the plot, again.

Many thanks for any help given.

Dave

Hi,
Please paste your code here.
At this moment it’s not possible to delete a database collection, We are working on it.
Roi.

HI Roi
Thanks for the help, the code is :

import wixUsers from ‘wix-users’;

import wixData from ‘wix-data’;

import wixLocation from ‘wix-location’;

$w.onReady( () => {

if (wixUsers.currentUser.loggedIn) {

$w("#button5").label = "Logout"; 

$w("#button6").show(); 

}

else {

$w("#button5").label = "Login"; 

$w("#button6").hide(); 

}

} );

export function button5_onclick() {

// user is logged in

if (wixUsers.currentUser.loggedIn) {

// log the user out

wixUsers.logout() 

  .then( () => { 

// update buttons accordingly

    $w("#button5").label = "Login"; 

    $w("#button6").hide(); 

} ); 

}

// user is logged out

else {

let userId;

let userEmail;

// prompt the user to log in

wixUsers.promptLogin( {"mode": "login"} ) 

  .then( (user) => { 

    userId = user.id; 

return user.getEmail();

  } ) 

  .then( (email) => { 

// check if there is an item for the user in the collection

    userEmail = email; 

return wixData.query(“Members-database”)

      .eq("_id", userId) 

      .find(); 

  } ) 

  .then( (results) => { 

// if an item for the user is not found

if (results.items.length === 0) {

// create an item

const toInsert = {

“_id”: userId,

“email”: userEmail

      }; 

// add the item to the collection

      wixData.insert("Members-database", toInsert) 

        . **catch** ( (err) => { 

          console.log(err); 

        } ); 

    } 

// update buttons accordingly

    $w("#button5").label = "Logout"; 

    $w("#button6").show(); 

  } ) 

  . **catch** ( (err) => { 

    console.log(err); 

  } ); 

}

}

export function button6_onclick() {

wixLocation.to(/Members-database/{Membership Number}update/${wixUsers.currentUser.id});

}

Dave

HI Guys me again

Really need to get this problem fixed, so today I spent three hours cleaning out everything of michaels code in my site and re doing it as per the wix tutorial on how to do it at Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com and guess what, it still wont work ???
Anybody got any ideas as to why it wont work ???
I’ll put the new wix code below so if anybodys good at wix code please take a look and let me know were i,m going wrong.

// For full API documentation, including code examples, visit Velo API Reference - Wix.com

$w.onReady( function () {
//TODO: write your page related code here…

});
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button5”).label = “Logout”;
$w(“#button6”).show();
} else {
$w(“#button5”).label = “Login”;
$w(“#button6”).hide();
}
});
export function loginButton_click(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then(() => {
// update buttons accordingly
$w(“#button5”).label = “Login”;
$w(“#button6”).hide();
});
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin({
“mode”: “login”
})
.then((user) => {
userId = user.id;
return user.getEmail();
})
.then((email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Members”)
.eq(“_id”, userId)
.find();
})
.then((results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Members”, toInsert)
. catch ((err) => {
console.log(err);
});
}
// update buttons accordingly
$w(“#button5”).label = “Logout”;
$w(“#button6”).show();
})
. catch ((err) => {
console.log(err);
});
}
}
export function profileButton_click(event) {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

Dave

Hi,
The code looks ok.
Can you please share a link to your site and specify the name of the page so we can inspect?
Roi.

HI Roi
Thanks for getting back to me, my site is at https://www.mvt.org.uk/ and the page is called log in page.
Do you work for wix support ?
Many thanks.
Dave

Hello Cheshiremvt, what are the IDs of your “login” and “profile” buttons? Are they “button5” and “button6” actually?

It appears you haven’t enabled the onClick event for the buttons, check those.

Best.

HI Abraham
Thanks for the help, just enabled the event handlers for login and profile buttons and it still wont work ???
Anyone got any ideas as to why it wont work ???
Many thanks.
Dave

I’m no expert, but this section of code looks funny to me:

$w.onReady( function () {
//TODO: write your page related code here…

});
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(() => {

I see 2 onReady statements, the one on the page by default and one you may have typed/copied in? I would delete the 2nd onReady, move the imports above the first onReady, and move the rest of the code into the first onReady statement.

Hi Dave.

I took a look at your site.

Please note, you have redundant section, please remove it:

$w.onReady(function () {
 //TODO: write your page related code here...

});

Now, you have 2 buttons on the page: “Login” - which has element ID button5, and “My Profile page” - which has element ID button6.

I see that your code (to respond to click events of those buttons) is written in the following functions respectively: loginButton_click and profileButton_click - this means that when clicking on button5 or button6 those functions will not be triggered. More info how the element events work can be found here: Velo Tutorial: Adding Custom Interactivity with Events | Help Center | Wix.com

In order to make to be invoked accordingly when the buttons are clicked, you have 2 options:

Option 1: Move the code from function loginButton_click to function button5_click and the code from function profileButton_click to function button6_click.

Option 2: Rename the ID of “Login” button from button5 to loginButton, and the ID of “My Profile page” button from button6 to profileButton.

This will make the code to be invoked when clicking the buttons.

Regards,
Genry.