Hi there, I see this has been asked before, but I can’t get any of the solutions to work from the community answers I’ve found. Can someone help please?
I’m trying to re-direct members to a specific page after they log in, but the code I’ve got does not work. I added it to the Master page. Code is below that I added to the masterpage.js, but it gives the following error message and does not work:
Error message - [/pages/Home.d7vax]:
Error count: 1
error: Parsing error: Unexpected token full (1:5)
[public/pages/masterPage.js]:
Error count: 1
error: Parsing error: ‘import’ and ‘export’ may only appear at the top level (4:1)
The error is pretty self explanatory, your import statements are within a callback function, they should only appear at the top level of the code, move the imports to the. Top of the page and it should be ok
Thanks again, but I’m afraid that is alien to me…I struggle with code. Can you be so kind as to provide what the change should look like to the code to get it working? I’d be very appreciative.
That’s totally fine. All of us were alien to code at some point! (:
Here’s the correct code. Simply delete any previous code inside your masterPage.js file and paste this:
import wixLocationFrontend from 'wix-location-frontend';
import { authentication } from 'wix-members-frontend';
authentication.onLogin(async (member) => {
wixLocationFrontend.to('https://www.sybaritesporting.com/');
});
Just to let you know what the users above suggested:
wix-users is an old API and is now depricated and replaced by the new wix-members-frontend, which we have used here.
import statements should always be at the beginning of your code, as you’d want to first import all the relevant libraries / APIs that are necessary for the code to run before actually calling them through the code. Else it will result in an error like the one you faced previously.
Looking at the error logs you’ve provided, it does seem that your homepage code might have some errors in it too, so make sure to check and rectify those out.