Router

This is dynamic page , and there is a repeater to display the content of dataset .

I mad a filter to the dynamic set so each user can see their own items.

Ok now lets chose any item and click on view more .

And there we go , every thing running smoothly .

The idea is :
If mike have an account and took the url of this item in the picture (this item _owner is mike)
And send it to another user called carl , carl will be able to see the content of this item .
This is the problem I have I want to make a security wall to check if the user is the owner of this item or not , if he is the owner show content and if it is not re direct the user to the homepage.

but I want to do it in a professional way with router or hooks
can you help me because I tried to read about it but I did not understand any thing and nothing work for me

this is my failed try with router :


import { forbidden, next, ok } from 'wix-router';

export function patient_afterRouter(request, response) {

    if (response.data._owner === request.user._id) {
        

        return next();

    }
    
    return forbidden();

    //TODO: write your code here...
}

i am struggling with this for many days and read all docs about router and hooks , any help ?

The request.user.id should be without an underscore (.id not ._id).
But why wouldn’t you run it as part of the query ? :

//routers.js
export function patient_customizeQuery(request, route, query) {
    return query.eq('_owner', request.user.id);
}

you did it
you just made my day , thank you much finally solve this problem
i did not think about this query at all i do not know why .
thank you again❤️

i have one more question if you have the time !

each user in my site can create an item with specific fields

and there is a dynamic page that view these items

but i added a filter to only show the items of the current user

my question is :
now i have a 100 items , the filtering process will take maybe a 1.5 second

but if i have a 5000 items , dose the filtering process will take a longer time ?

and if it will take a longer time , is there any method to make the process faster(like using References) ?

Querying or filtering collection with 5k records will take more time (but I can’t say how significant it’s going to be. You’ll have to test it).
There’s a way to make it faster by creating an index. But this feature is in beta phase and not available to all users (I think it’s available to users in the UK).
See:

https://support.wix.com/en/article/content-manager-adding-an-index-for-your-collection