Setting 'members only' to specific, individual dynamic pages

Hi, I’m currently stuck on a certain hurdle and can’t think of how to get around it - would greatly appreciate any help!

I’m putting together a site containing a variety of cooking recipes and currently have all of the recipes contained in a single ‘Recipes’ collection. I’m then using datasets and repeaters to display these recipes on category pages, which then lead to the recipe detail pages.

My issue is I need to make specific recipe detail pages only available to users who are logged in to the site. I’m aware of the ‘members only’ feature, but I’m not looking to set all of the dynamic pages (recipes) to members only, only specific ones.

I tried of creating a separate collection for all of these members only recipes, but this wouldn’t work as I still need all recipes to be displayed in the same repeaters and can’t find a way of connecting a repeater to two different datasets.

If anyone could help me I’d be eternally grateful!

Hey Josh. So if I understand, you have specific recipes in your collection that you want only to be accessed after someone has logged in. But since it’s only specific recipes, you don’t want to turn the entire dynamic page into a member’s only page.

If that’s right, one of the ways you could go about this is:

  1. Add a boolean (true/false) field to your database collection, called isMembersOnly
    This way you can control data per-item without creating a members only version of the recipes collection.

  2. Check if a visitor is logged in on a members only recipe page
    This allows you to check not only if the person is logged in or not when they view that recipe, but also what roles that member has on your site, which is good if you have tiered plans based on the types of recipes people can view

Note , with this method you’re going to have to give them that Medium, New York Times user experience, where they’ll be able to see the recipe first for a bit, before it prompts them to login. This is because wixMembers frontend APIs only run once the page code has finished loading.

The code could look something like this on your product details dynamic page:

import { authentication, currentMember } from 'wix-members';
import wixLocation from 'wix-location';
//...

/**
* This function needs to be attached to the dataset's 'onReady' event, through the Wix Editor UI.
*/
export async function dynamicdataset_ready(){
  // Get the entire current item
  const recipe = $w("#dynamicdataset").getCurrentItem();
  
  if(recipe.isMembersOnly){ //Check those member permissions!
    
  const member = await (currentMember.getMember());
    if (member) console.log('Is Logged In')
    else {
        try {

            await authentication.promptLogin({ modal: true, mode: 'login' })
            console.log("Logged in successfully")
        } catch (err) {
            console.error("Didn't successfully login - ", err);
            wixLocation.to('/home');
        }
    }  
  }
} 

Hope this helps.

Hi, I would like to understand the solution too, but I think the answer field is empty. I would really appreciate a help on how to make certain Dynamic (Item) pages restricted to members/subscribers only.