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'); }) }) })
Hi Jameson!
The image isn't very clear. Would be happy to look into your site if you'd share a link to your published version/editor.
Note that only authorized personnel can inspect your site so rest assure other users won't be able to enter the link (for the editor).
Anyway, item ID and _ownerID are two fields that are created automatically upon item submission to the collection (you can see them under 'Visible Fields' in the collection page).
The value of itemID is unique and so - two items will never have the same ID.
About the _ownerID - it is also unique but since it represents the ID of the user who created the item, if there's no limitation on how many items/records can a user create, there may be more than one.
When talking about profile page/user page we obviously want to limit it.
Now. In order to navigate to one's dynamic item page you'll need to find the correct path to follow (much as you did in the first part of your code in the original post). It should look something like this:
if (wixUsers.currentUser.loggedIn) { wixData.query("yourCollection") .eq("_owner", wixUsers.currentUser.id) .find() .then((results) => { if (results.length > 0) { let url = results.items[0].id ; wixLocation.to('/yourPath/${url}') } }) }
Let me know if it works for you!
Doron.
P.s.
As for the new question regarding the paid section - please post a new thread so other users in the future can distinguish and profit from your curiosity. :)