Hi and many thanks in advanced.
I’m new to this and have no coding experience.
I recently discover the beauty of Dynamic Data and Dynamic Page. I’m really excited as this can help achieved the goal towards Virtual Admin support.
Instead of sending and resending (when customer misplaced or forget) the User ID and Password* individually, I’m thinking I can
create a Data collection contain or link to Login Email or PrivateMembersData Dynamic (I don’t mind if I have to manually add / import the Login Email as a 1 time effort)
create fields and fill the data collections with customer specific *login info, etc at the admin level
Display these info when customer login to their member page
I tried by adding an ‘input text (email)’ in the My Orders page, see below so that when submit it will direct to the customer specific dynamic page to display the mentioned. But it doesn’t seems to work, it always redirect to the same ‘dynamic page of the first customer on the dataset / collection’
Can I simply display the required *Customer Login ID and password directly on a new Private page or I was on the right track to use Dynamic Pages?
I’ve bring trying this for the last 2 weeks whenever I find time and Wix Support direct to me here. Hope you can understand (I believed is a simple) requirement and look forward to some guidances.
When you take their email address on the private members’ page, the first thing you need to do is to check is if the current logged in member is the owner of that email, and if he’s, then retrieve the data from the database and display it. This is called authorization , which basically mean that members can only see what they’re allowed to see, or should see, without having access to others’ data.
Let’s check if the current logged in member is the owner of that email or not, to do that, we need to put the code on the server ( backend ) for security reasons, and for that, we need to create or use an existing JavaScript Web module ( JSW ).
In the code bar section on the left:
Go to the " Backend " section and click on the ( + ).
Click " New Web Module ".
Rename it to whatever you want.
For this example, I’m going to call it " members.jsw ".
// Backend: backend/members.jsw
// import Wix Users and Wix Data
import wixUsersBackend from 'wix-users-backend';
import wixData from 'wix-data';
// Create a function to check the the provided email - This is a helper function
function checkEmail(email) {
return wixUsersBackend.currentUser.getEmail().then(result => {
if (email === result) {
// Grant access because the member is the owner
return true;
} else {
// Reject access
return false;
}
})
}
/* Create an "exported" function that will get the data of the current logged in member based on the email: */
export function getData(email) {
/* First thing we should do is to check if the current member is authorized
to access the resource or not, and if he's authorized, retrieve the data. */
// To check authorization, we'll call the helper function we declared above.
return checkEmail(email).thne(isAuthorized => {
// "isAuthorized" is true if the user is authorized, and false if otherwise
if (isAuthorized) {
// Now you can retrieve the data
} else {
/* If the user is not authorized, reject the promise and return an
error to the client */
return Promise.reject("You don't have access to this resource!");
}
})
}
Now on your page, start by importing the function into your page.
import { getData } from 'backend/members.jsw';
// On your submit button:
$w('#submit').onClick(() => {
// Store the email value
const email = $w('#email').value;
// Call the function with the email as an argument to get the data
return getData(email).then((result) => {
console.log("The final result is:", result);
// Now you can see the result in your console.
}).catch(err => {
console.error(err);
// Show an error for the user;
$w('#errorMsg').text = String(err);
})
})
@ahmadnasriya
Q1: I’m looking at the 2nd script you provided why do I need a Submit button?
Are you suggesting that I keep the input email and submit per my screenshot and display in a dynamic page?
Q2: Can I not just display the specific “customer info” the member private page (ie without Dynamic Page)?
@ahmadnasriya Haha I added the Email Input + Go as ‘my’ silly workaround, thinking I can ‘cheat’ the and display via Dynamic page!!
So I can delete this 2 rows
$w( ‘#submit’ ).onClick(() => {
// Store the email value const email = $w( ‘#email’ ).value;
and just add text box and link to my dataset to display the required field / info right? Do I still need any codes?
@ahmadnasriya Oh no … I really under estimate the complexity. I thought this can be done easily by creating a dataset (a new collection, add field of data we need to inform each customer), duplicate and reference the email field to the PrivateMembersData and display using Dynamic page.
@ahmadnasriya
Sorry Ahmad, I think my screenshot was misleading. In fact, I’m quite confused now. After reading your codes and messages repeatedly, I like to recap my requirement and attempt to implement with a list of Question cum Step approach. Pls correct me if I’m wrong.
Requirement: Display Member’s specific information (all specific customer content/info are created by me for their easy reference) at their own member page.
My assumed associated Steps / questions to achieve this requirement.
Q/S1) I should create a Collection (name students) and reference to Email of PrivateMembersData , correct?
(then add fields and fill in the customer specific information)
Q/S2) Add / Create the // Backend: backend/members.jsw code you provided, correct?
Q/S3) Add Text field / box(es) at the existing Member’s ‘My Orders’ page as follow, correct?
(example below, to display the additional customer specific info)