ah i solved it!
Dual database setup:
In database 1 (the DB that holds login info) the field “loginEmail” is the primary field
in database 2 (the DB that holds profile info) set OwnerEmail to primary field as well
(not sure if this is required)
PAGE 1:
Register page:
page has:
1 button for login/logout
and
1 button that is hidden/shown to nav to profile update/creation
the code on the page:
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w( “#loginButton” ).label = “Logout” ;
$w( “#profileUpdateButton” ).show();
}
else {
$w( “#loginButton” ).label = “Login” ;
$w( “#profileUpdateButton” ).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( “#loginButton” ).label = “Login” ;
$w( “#profileUpdateButton” ).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( “NameOfYourDatabase” )
.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,
“FieldNameOfYourEmailinDatabase2 aka ownerEmail” : userEmail
};
// add the item to the collection
wixData.insert( " NameOfYourDatabase " , toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w( “#loginButton” ).label = “Logout” ;
$w( “#profileUpdateButton” ).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
export function profileButton_click(event) {
[wixLocation.to(](wixLocation.to(‘/Someadres) [’/SomeAdres](wixLocation.to(‘/Someadres) YouWrote /${ ownerEmail }’ );
}
PAGE 2:
make a dynamic page that uses the ownerEmail (ProfileUpdater/${ownerEmail}) for adress
this page has:
dataset 1 (read only) which hold member log in data
and
dataset 2 (read & write) which is where the profile will be created
text input: inputYourLoginEmail
and
text input: inputPageOwnerEmail
and
lots of user input fields for profile creation/update connected to database 2
and
1 submit button
and
is owner logged in check
the code on the page:
On page where button is hidden or shown:
$w.onReady( function () {
//prepare datasets
$w( " #dataset1 " ).onReady( () => {
$w( " #dataset2 " ).onReady( () => {
//get the values from the inputs
let value1 = $w( " #inputYourLoginEmail " ).value;
let value2 = $w( " #inputPageOwnerEmail " ).value;
//check the values against each other
if ( value1 === value2) {
//hide or show stuff
$w( " #submitButton " ).show(); //shows the submit button on this page
} else {
$w( " #submitButton " ).hide(); //hides the submit button on this page
}
}); }); });
PAGE 3:
This page is a dynamic profile page with member access
and the same “is owner is logged in check” as above.
This shows info and buttons depending on if owner is logged in:
inputs and datasets:
dataset 1 (read only) which hold member log in data
and
dataset 2 (read only)
text input: inputYourLoginEmail
and
text input: inputPageOwnerEmail
and
lots of user input fields for profile creation/update connected to database 2
and
1 submit button
the code on the page:
On page where stuff is hidden or shown:
$w.onReady( function () {
//prepare datasets
$w( " #dataset1 " ).onReady( () => {
$w( " #dataset2 " ).onReady( () => {
//get the values from the inputs
let value1 = $w( " #inputYourLoginEmail " ).value;
let value2 = $w( " #inputPageOwnerEmail " ).value;
//check the values against each other
if ( value1 === value2) {
//hide or show stuff
$w( " #someButtonOrTextOrImage " ).show(); //shows stuff
} else {
$w( " # someButtonOrTextOrImage " ).hide(); //hides stuff
}
}); }); });
There is probably an easier way to do this without using inputs and instead comparing databases directly, but im not a coder so use this at your own risk.
Oh and remember to set the check inputs to “hidden on load”.