Hi,
I am using Magic (How to Plug the Magic Login Form into Webflow | Magic) to protect pages. I need to protect Collection Pages, there is some Javascript that looks at the current page and matches it to an array. But I do not have the skill to make the array a path and include all the pages in the Collection.
The array
let privatePages = [
‘/profile’,
‘/incidents/’, // This is the slug path to my collection…it works if I use the absolute URL /incidents/incident-1… but I need to know if I can use something like . to accept any collection page.
];
if (privatePages.includes(currentPath)) {
window.location.replace(‘/login’);
The current path is formed by
const currentPath = window.location.pathname;
I have tried many forms to get my array to match the window.location.pathname. Without success. I could easily do this in C, but I seem unable in Javascript (still a novice).
Anyone have any ideas.
Chris