Recently I posted a thread about making logout() work properly when you are using a custom member login page (here: https://www.wix.com/code/home/forum/community-discussion/logout-redirection-issue ). So I have my login page working fine, except that redirects to my member pages by a person who is not logged in bring up the canned Wix login page and not my custom one. This can happen either when 1) you call logout() from your code or 2) there is an external browser request for a restricted page.
I decided to take control of this issue by writing a router for my restricted member pages. All the router needs to do is to redirect the request to my custom login page if the user is NOT logged in, and allow the request to pass through unchanged if the user IS logged in. The problem I have encountered is that when I insert:
import wixUsers from 'wix-users';
so that I can code:
if (wixUsers.currentUser.loggedIn) { ...
into router.js I get an error.
So how do I make my router action depend on the login status of the user?
The following example illustrates redirecting based on login:
Stripe Payment Processing
Integrate the Stripe Payment processing system into a site. Three levels of user access are demonstrated: visitor, freemium (registered), and premium (paid).
Hi Yisrael would you mind pointing me to the specific part of the thread which is relevant?
My situation is as follows;
I have custom login and register pages already built and both are working correctly.
mysite/admin is member protected and only allows access to users who are already logged in.
if the user is already logged in through my own methods then access to mysite/admin works as expected and no issues are found.
if the user is not already logged in, then wix appears to hijack the view and redirects to the standard wix login which is what I am trying to stop. Also, if the user is on mysite/admin and then logs out, the user is then redirected to the same page.
When the user visits the mysite/admin page without being logged in, how do I intercept this call to route to my own login page instead?
You will need to use Routers for handling the redirection of site visitors. The example contains router code, which you can learn from, in a routers.js file in the Backend:
Hi Yisrael. I have been playing around with routers since last night and feel relatively happy using them so far. Unfortunately, I now have another issue which appears to be throwing a 500 error when visiting a router page. I believe that adding an import statement to wixUsers from within the routers.js file is causing an error and wondered if you could try and reproduce this?
I have a basic router set up for mysite/admin. In the routers.js I have the following code which is working perfectly and obviously just passes all traffic through to the relevant page;
import wixRouter from “wix-router”;
export function admin_Router(request) {
return wixRouter.ok(“admin”);
}
However, as soon as I add an import statement to the routers.js file as follows, I immediately receive a 500 error on my published site.
import wixUsers from “wix-users”;
As soon as I take it out again it starts working. What’s up here?
Are there any plans to improve the intellisense functionality at all here? I generally love the product, but I have spent hours trying to work out what was going wrong. I appreciate that the answer is in the documentation, however it didn’t even occur to me that I wasn’t able to use the same functionality. If the editor had told me that ‘wix-users’ didn’t exist it would have made things a ton simpler.