Hi again,
lots of spamming notification of wix code forum.
I get more than 50 spamming per day : (
let answer one by one : )
Hi again,
lots of spamming notification of wix code forum.
I get more than 50 spamming per day : (
let answer one by one : )
Have you add the API?
import wixLocation from 'wix-location';
About navigation it may refer to name in your editor like below,
wixLocation.to("/referToYourPage");
For “identity” you can have a look with inspiration below,
Although I suggest to use a button more than auto navigation to specify dynamic page, the code may like below : )
It’s because a part from users role, it sims does not have other ways to do the navigation without add dataset to your editor.
export function loginButton_click() {
// user is logged in
if (wixUsers.currentUser.loggedIn ) {
// log the user out
wixUsers.logout().then( () => {
// update buttons accordingly
$w("#loginButton").label = "Login";
$w("#profileTable").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("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 must always need...
"_id": userId,
"email": userEmail,
//Var identity value before insert to database, you also can use hook to do so.
//If you are using boolean, it may refer to true or false.
//If you are using text, it may refer to a string you want.
"identity": false
};
// add the item to the collection
// refresh() may let the dataset can get the new data, if member was first time join your website
wixData.insert("Database", toInsert)
.then(()=>{
$w("#dataset").refresh();
});
}
// update buttons accordingly
$w("#loginButton").hide();
$w("#profileTable").show();
// Get member's identity value from dataset...
let identity = $w("#dataset").getCurrentItem().identity;
//Doing navigation...
if (identity === false) {
wixLocation.to("/pageForNonEmployees");
} else if (identity === true) {
wixLocation.to("/pageForEmployees");
}
} ).catch( (err) => {
console.log(err);
} );
}
}
Hello Heson Li
I think for such a teapot as I need to tell everything on the steps ![]()
Can this be done through TeamViewer? It’s just difficult for me to explain the problem …
Here’s what’s on my page:
And if he’s a client, I need him to get on this page
This is the code I tried to edit with the navigation.
// За полной документацией по API, включая примеры кода, зайдите на 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(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
} else {
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
}
} );
export function loginButton_click() {
//if loggedIn then loggedOut
//если loggedIn, то loggedOut
if (wixUsers.currentUser.loggedIn) {
wixUsers.logout().then(()=>{
//Update button…
//Кнопка обновления …
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
});
} 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,
“identity”: false
};
// add the item to the collection
// добавить элемент в коллекцию
wixData.insert(“Members”, toInsert).catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
// кнопки обновления соответственно
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
// navigate to page
// перейти на страницу
let identity = $w(“#Memberdataset”).getCurrentItem().identity;
if (identity === false) {
wixLocation.to(/Members/${wixUsers.currentUser.id});
} else if (identity === true) {
wixLocation.to(/Members/Employee/${wixUsers.currentUser.id});
}
} ).catch( (err) => {
console.log(err);
} );
}
}
I tried to translate it there myself, it’s after the sign (//)
Here’s what happens on the published site
For example, this is the main page of the site. Which can view any guest.

The login screen appears.

There is this

On the site there is this
“Мой профиль” translates as - My profile
Now that the client has reached his page, he needs to click here

In the code this button is called like this

When the client clicks on this button

The collection automatically adds its data to further define its role

Then according to the idea he should get on the page intended for clients. The page is dynamic, that would not create a separate page for each client and not edit the code for each one. In addition, on his profile page only his data is displayed and not the data of another client. The program identifies it and displays only its data.
By clicking on this button, the customer must go to his profile
It looks like this
But this does not happen because the code does not have this function

According to your code, I imagined that this would happen after the click of this button

But in principle, after clicking this button, the input to this page does not interfere

He crossed here

This does not happen
In addition to all of the above, there are also employees with their dynamic page
You said that customers and employees should be in the same collection or database
But when at least employees under their own login even though customers click on this button under their login

The collection automatically registers the entry to the client’s dynamic page

And I do not understand what you need to connect to this database

Here I am so stupid ![]()
Strictly speaking about this and I ask for your help. Because of this, I have not even started the code for which I was contacted from the beginning.
Thanks to navigation, I want to create an input not only for clients and employees but also for the administrator and the manager. The administrator will change the schedule to follow the scores, and the supervisor will see the overall robot school. For each of them you need to have a diamonic page. Because there may be several administrators responsible for the work done. Judging by my concept and your code it can be done. Especially you are such a magician
Thank you very much for helping !!!
Even better, the registration process would look like this:
For example: the visitor of a site passes registration and automatically without my permission it is registered, but after this procedure it gets on page here with such text:
“Thank you for registering, please wait while the administrator configures your Personal Account”
After that, in the edit panel of the registered visitors’ role, the supervisor assigns a role to everyone by finding their email in the table.
It would be better if this was a text version and not boolean
I mean the role in the table
After that, a time later, the visitor comes through the login page already in the personal cabinet with the account of his role.
Hi,
It sims to be a big scale but it also can become simple
Although I don’t know the language, I can suggest you an inspire.
Just wait a moment, I may create a quick demo to let your project success.
Many thanks!!! I will wait…
Hi,
I have checked the api reference and test on a blank project.
The result is that
Code of dataset cannot add inside login.Therefore, “identity” cannot use for navigation.
Your concept is right, it only can use “wixUsers.currentUser.role”. however, options of roles only have “visitor”, “admin” & “member” now.
In the other way to do the same result is that
It was a trick more than a coding.
After login,
Navigate to a dynamic Page < only serves for site members
The concept sims to a profile page
After that A button will show.
Hello! And if then use different databases. That would click on the button “My profile” link went to the page in view of its role. But at the same time the page used his ID and did not go into the office of another participant. And he would be able to look only to himself.
That is, something like this, but to everyone on their page.


Option with button “A” is also good
Hi again,
I have created a quick demo for your case, it uses a little trick to do the result you want.
It was very simple.
Let try it.
https://arctiinasestorage0.wixsite.com/mysite
Account for try,
Identity: members
ac: test02@test.com
pw: 1234
Identity: employee
ac: test03@test.com
pw: 1234
Identity: manager
ac: test04@test.com
pw: 1234
Identity: admin
ac: test05@test.com
pw: 1234
Enjoy.
Heson
It’s just cool !!! You really are a magician
What will happen if none of the registered will not be assigned a single role?