Display Member Specific Info (Dynamic Page vs Member Private Page)

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

  1. 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)
  2. create fields and fill the data collections with customer specific *login info, etc at the admin level
  3. 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’

I then tried adding some code I pick up from the forum as below:
$w( ‘#button40’ ).onClick((event) => {
let loginemail = $w( ‘#input1’ ).value;

$w( '#dataset1' ).setFieldValue( 'field title' , (loginemail)); 
    $w( '#dataset1' ).save(); 
    }) 
}) 

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.

#DynamicPages #PrivateMembersData #dataset

Hey there :raised_hand_with_fingers_splayed: And welcome to the community.

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:

  1. Go to the " Backend " section and click on the ( + ).

  2. Click " New Web Module ".

  3. 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);
    })
})

And that’s it, hope you find it useful.
Ahmad

Thanks Ahmad for your prompt reply and detail steps … I will definitely try this later tonight. :smiley:

You’re welcome @hq1 :wink:
Looking forward for your feedback.

@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)?

Hey @hq1

Q1 A: The submit button is the “Go” button in your screenshot.
Q2 A: You don’t need a dynamic page, you can retrieve the data and show it to the user.

Further note: You can get rid of the email form, and just show the details of the member based on his email address.

@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?

@hq1 Yes you still need some code, but not the above unfortunately.

@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 Why u don’t suggest Dynamic page? Is it because Dynamic page is not suitable or not required as it is better with code?

@hq1 Because you don’t need a dynamic page to pull data out of a DB, who ever visit this page will get HIS data displayed.

@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)

Q/S4) Link each Text field / box(es) to the Students Dataset as follow, correct?
(Do I need to add any filter in the Dataset?)

Q/S5) add the code " import { getData } from ‘backend/members.jsw’ ;" etc you provided to this page, correct? What other codes do I need?

Pardon for the long message… hope I’m making sense now. Thanks

Did you get a resolution to this? I’m in need of the same i.e. no submit button, just whatever member is logged in sees their details on the page.