Wix Experts how can I Redirect on 403 ?

When a member of my site logged out, click on link https://costieraslow.wixsite.com/ilmiosito04/Members/Confirm/cc0d2bae-d5c7-4228-b1df-9944598084e5, dynamic page with his user id (it’s only an example), of course he gets a 403 forbidden page.
But I would like redirect him on my login page.
I tried following code in router.js, but it doesn’t work.
How can I solve this ?
thanks in advance
Mauro

[ router.js ] in Backend

import {redirect} from ‘wix-router’;
export function Members_afterRouter(request, response) {
if(response.status === 403)
return redirect(“https://costieraslow.wixsite.com/ilmiosito04/cloud”, “301”); }

or

import wixLocation from ‘wix-location’;
export function Members_afterRouter(request, response) {
if(response.status === 403) wixLocation.to(/home/);
return response; }

up

Hi Mauro,

You can write your own router to take care of “special” pages. Refer to the wix-router API for full details.

Yisrael

1 Like

Hi Yisrael,
believe me I read everything, but I wasn’t able to get it, perhaps it’s my fault.
But could you suggest to me:

  1. if my solutions are on the right way or not
  2. what’s the right way, also in general schema

thx in advance
Mauro

Up

Hi Mauro

Did you find how to do this.
I m need of the solution for this exact problem. kindly help me with your solution

Hema

Hi Mauro Vento Avyno,

I hope you already found the solution. I’m posting the answer for other people who may have the same question.

Luckily, I found the solution after playing around a bit.

Open Dev Mode → Hover over your dynamic page and click on the “…” → Click on settings → under Page Info, you’ll find an option to “Add hooks”. Click on it
->select beforeRouter option.

A router.js page gets created. Here you can type in the following code:

import wixUsers from ‘wix-users-backend’ ;
import { redirect, next } from ‘wix-router’ ;

export function member_beforeRouter(request) {
console.log( “reached router” );
if (wixUsers.currentUser.loggedIn) {
console.log( “user logged in” );
return next();
} else {
console.log( “redirecting to home” );
return redirect( “https://www.kaviartstudio.in” );
}
}

My database name is : Members
The link I wanted to redirect was the home page.