Below is the standard LOG IN code to log in and redirect an existing member to a custom dynamic page (after member userid is inserted into a database collection)
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#socialLogin”).label = “Logout”;
$w(“#button9”).show();
}
else {
$w(“#socialLogin”).label = “Login”;
$w(“#button9”).hide();
}
} );
export function socialLogin_onclick() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#socialLogin”).label = “Login”;
$w(“#button9”).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(“socialclients”)
.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(“socialclients”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#socialLogin”).label = “Logout”;
$w(“#button9”).show();
} )
. **catch** ( (err) => {
console.log(err);
} );
}
}
export function button9_onclick() {
wixLocation.to(/acct/update/${wixUsers.currentUser.id}
);
}
I would like something just like this, but direct a brand new customer to the dynamic page (site setting on auto accept member)
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function (){
$w('#signup').onClick( **function** (){
let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
wixUsers.register(email,password)
.then(()=>{
wixLocation.to('/signup');
})
})
})