Page restriction
Created 6 months ago by cyno

Hi, So I'm trying to make a page only accessable when user is logged in. It's working on views/pages I created in a module, but not working for pages I created on the admin dashboard. I've tried restricting it in page options, which makes it disappear from the menu (I don't want that), also tried overriding the route in the theme service provider (not working either). Any ideas?


'profile'  => [
            'anomaly.module.users::role' => [
                'user',
                'admin',
            ],
            'anomaly.module.users::redirect' => '/login',
            'anomaly.module.users::message'  => 'Please log in to continue.',
            'uses' => 'Anomaly\PagesModule\Http\Controller\PagesController@view',
        ],

ryanthompson  —  6 months ago

The pages module has it's own "allowed roles" in options that you can do this with. Keep in mind admin's have access to everything so it won't apply to you while logged in.

cyno  —  6 months ago

Problem is if I set allowed roles if im loggod out its not visible in the menu. Also even if set it, for some reason if i access the url i can still see the page.

ryanthompson  —  6 months ago

Ah you're using structure for your menus. One way to solve this would be to use Navigation for your menu so it's independent.

Double check on that allowed roles cause if you are indeed logged out you won't see a protected page unless the guest role is allowed.

cyno  —  6 months ago

Also om monday im gonna send u every info regarding this.

cyno  —  6 months ago

So I've double checked it, and indeed if its set to Admin, User as allower roles, it dissapears from the structure. But if I access the url directly, the page still loads (you can check at dev.hustle-app.com/profile). Seems like a wierd bug to me.

cyno  —  6 months ago

@ryanthompson any updates on this by chance?

ryanthompson  —  6 months ago

This is what is protecting pages: https://github.com/anomalylabs/pages-module/blob/2.6/src/Page/PageAuthorizer.php

Can you find anything strange about your issue here?