Redirect to public user profile on wixLogout

Hi everyone, I am new to wix and coding.
I have a members area, with my personal profile, where I can update my information. And I have dynamic pages, for other users, whose information I can not update. When I am on my personal page (I am logged in), and I try to log out, it shows me the same page, however with placeholders (“my full name”, “my birthday”, etc.) which are the dynamic elements from my data collection.

I need it to be redirected to the “public” dynamic page, which url is shown here:

That is the field key I am trying to connect it to:

I have tried some code, but nothing works so far. Can someone help?

THANK YOU!

import { authentication } from ‘wix-members’ ;
import wixLocation from ‘wix-location’ ;

authentication . onLogout (() => {
/ /wixLocation.to(“/${link-userprofiledata-title}”);
wixLocation . to ( “/userprofiledata/link-userprofiledata-title” )
});

This one will not work…

import { authentication } from 'wix-members';
import wixLocation from 'wix-location';


authentication.onLogout(() => {
    //wixLocation.to("/${`link-userprofiledata-title`}");
    wixLocation.to("/userprofiledata/link-userprofiledata-title")
});

After logout a refresh of website takes place (as i know), right?

So that means → AFTER → LOGOUT → there is nothing and no code will run!

You can find the same code-situation in the Velo-Api…

How to solve your problem ?

Instead of trying to redirect on → LOG-OUT, you can save some data in the Wix-Storage (local or session) to tell your code to do the redirection, after a LOG-IN.

Store your Logout-Information inside wixStorage…

Write some code in the onReady-Section on your page, which will automatically take a look onto the stored informations inside the wixStorage, after page-refresh.

Thank you for this quick reply! I get the part with the login, instead of logout, however, how would that code look like? Trying to get the value from fieldkey=“fullName” and connect it to wixlocation…

I tried a couple of things, nothing works…


import {local} from 'wix-storage';

$w.onReady(function () {
    //let value = local.getItem("fullName"); // "value"
    let value = item[1].fullName; 
    wixLocation.to(`/userprofiledata/${value}`);
    })

@stas-vaisman

The process works like…

  1. FIRST → set the value inside → Storage → using a → key.
  2. SECOND → get the value → using the key → you have created in FIRST-step.

Setting the value → using a key → inside → Wix-Storage

import {local} from 'wix-storage';

local.setItem("key", "value");

This is your VALUE, right —> /userprofiledata/${value} ???

import {local} from 'wix-storage';

let myValue = JSON.stringify(`/userprofiledata/${value}`)
local.setItem("key", myValue);

You just setted-up your value inside storage.

I think the second part is self-exploring.