I would like to do the following:
-
User navigates to a router controlled page
-
Router determines if the user is logged in.
-
If logged in, continue with routing
-
If not, allow the user to log in
-
Check what Collaborator roles (as opposed to Member roles) the user has, and determine if that user has permission to view the router controlled page.
-
If user has the right permissions, route them to the page
-
If the user does not have the right permissions, route them to some other page
How can I do step 4? When you navigate to a router controlled page, the router code runs, then once routing is done, your page code runs. promptLogin is only available on the client, so somehow, the router has to detect the login status, then tell the page about it so the page can prompt for login.
I tried using the router to detect if the user was logged in, then send data back with the router response, but this didn’t work. It’s really slow, so you see the page for a second or two before the login screen comes up. Yeah, I could hide everything on the page, but this all seems really hokey. Is there any way I could make better use of the router to do this?
I think it must be possible, because if I use Wix’s built in page permissions (for example, only Admin can look at this page), and then I navigate to the page, Wix forces the login to happen. If I just cancel out of the loginPrompt, Wix redirects me back to the home page. I’m not sure how this works, or if the same mechanism is available to me. I do know that when Wix does the intercept, my masterPage.js and pageCode onReady don’t run. I think Wix is intercepting before any page code or onReady is called. I don’t suppose we have access to the same interceptor…
Unfortunately, I’ve read everything I can find about Wix routing, and the docs and examples are inadequate in this area.
Barring that…the only reason I’m doing this at all is because I was hoping to use Collaborator Roles, and not Member Roles. I could skip all this nonsense if I use Member Roles because I can set up all the router page permissions to the member role. But my hunch is that for what I’m doing, I want these people in Collaborator Roles, not Member Roles.
I thought that using Member Roles was for setting up a whole Members area and allowing people/customers/general public to request/sign up for your site. I really don’t want that. I just want a few of the store’s staff members to be able to get in and do some things. There are other things they need to do as well, like post Blog articles and access the media manager. This is why I was using Collaborator Roles. Should I be using Member Roles instead?
Thanks in advance