Need to close a private page, clear cookie & redirect

So I have a single private, password protected page for each client. The page includes log in and password information for that client to other sites.

When the client is finished with the page, I want him/her to click a button, clear the log in information they used to get to that page, and redirect them to our main website.

I’m a designer … not a coder. I have no idea how to do this. Please help.

Thanks.

$w.onReady(()=>{
	$w('#yourButtonIDhere').onClick(()=>{
		myFunction(); //<<--- the click onto the button will start your function
	});
});
function myFunction() { //this will be your function which will get started...
    // code here all the code for all your processes, what shall happen?
    // when button was clicked....
    //...and function is running...?
    //....	
}

…and redirect them to our main website.
https://www.wix.com/velo/reference/wix-location/to

Thank you for taking time to reply, but I’m totally confused.

So I enter the code from block 1, as is? That starts “myFunction”?

Do I add any code to block 2?

If, at that point, I didn’t add any more code, what would happen?

Is the wix-location/to code put in a new block?


Finally, I want to make sure that once the users exits the private page a user would be required to enter the page log in and password again to see that page.


Sorry to sound like a dunce. But I know next to nothing about javascript.

@rich50877
Place first CODE-BLOCK onto your wished page.
The first CODE-BLOCK will start a funtion → called → myFunction.
You can name the function like you want, in most cases the function-name has always to do with it’s current function-action.

Replace the ID of your own butten with the PLACE-HOLDER-ID

$w('#yourButtonIDhere').onClick(()=>{.......}
function myFunction() {
   //this function is an EMPTY-function and it does absolutely nothing else existing
}

Open console log in your BROWSER or in your Wix-Editor.
To open CONSOLE for example in CHROME-BROWER → Press F12 & navigate to → CONSOLE. Take a look onto given RESULTS, do you recognize something?

function myFunction() {
   console.log("The same function one more time, with first ACTION!!!")
}

Generate your code inside the function. For example → let’s navigate to “google” after a button was clicked…

import wixLocation from 'wix-location';

$w.onReady(()=>{
   $w('#yourButtonIDhere').onClick(()=>{
      myFunction();
   });
});

function myFunction() {
   console.log("Let's go to ---> GOOGLE !!!")
   wixLocation.to("www.google.com");
}

@russian-dima This seems like it’s pretty straight forward and easy, but …

it doesn’t work.

Ok your first lesson learned​:grin::rofl:
NEVER just copy and paste what other gives/provides you xD.

If you have read the informations inside in the given link above, you would see/find the following…


Especialy this…

Now do some testing and give it another try. :wink:

And it seems like you have an ERROR on your page (in your script)…

And another clue to your not working CODE is…


You never got this message in your CONSOLE, right?

So now try to figure out, which one of the 3-tips was the right one :wink:

@russian-dima The error in the script is the problem. And I don’t know what to look for.

No, I never got the message in the console.

@rich50877
Test the code on a totaly new empty site/page and see if it works there.
If so, than something with your current page is already not OK.

It actually worked, this time, but … how do I make it so the user needs to re-enter the password to log in again?

@rich50877
Read this…
https://www.wix.com/velo/reference/wix-users/logout

@russian-dima Do I put that code before the wixLocation.to code line?

And, can I send you small gift via PayPal for your assistance?

@rich50877 If you want you can do a donation on my site. It’s on you.
You will find my contacts in my profile.

When you log-out, your page will immediatelly be refreshed (try it out).

What you will need is a command called —> onLogin <----

That means…

  1. You press → Logout → you will be logged out.
  2. Page will refresh → page loads again.
  3. Now you need something which will react to your login (when user logs in again). → onLogin.

Take a look here to all the given possibilities…
https://www.wix.com/velo/reference/wix-users

There you will find all you need. If you need further help just write here again.

I am still not sure what exactly you are trying to manage, but if it is some kind of a custom Login-page or something like that, take a look on this example of my own.

On this CUSTOM-LOGIN you can see all it’s behaviour.

-Log-In
-Log-Out
-Register
-Passwort-Coformation
-Forgot PW and so on.
-One already integrated and activated FEATURE for DEMO → Switch on and off the INFORMATION-POP-UP-BOx.

https://www.media-junkie.com/login-page

Take also a look to the described behaviour after a log-out.

@russian-dima Here’s the site. clientportal.rsavirtualmarketing[dot]com

If you click on Il Forno Classico, under the Client Logins menu, it will take you to their private page. When you click the LOG OUT button, I want the user to be logged out and redirected to our public page.

Everything works “exactly” the way I want it to, except the log out. Dunno where to include it here.

And, yes, I will be rewarding you for your kind effort.

@rich50877
After a LOG-OUT, you normaly will stay on the same page (just not as a member of the site if a defined ID anymore) as i know.

How could look like your steps to to fame and fortune :grin:

  1. User-Log-out.
  2. User will be still on the same site after log-out.
  3. Now you need to redirect after log-out.
    As i know the log-out takes action immediately, so you have no chance to do it by a -->.then() or something.

Possible solutions…

  1. Before logging out, placing some value in the wix-storage → some kind of a command, which can be used after log-out-process to know what to do next.

I explain.
After USER has logged out the site will be refreshed. You have no chance to do the redirection. But after you have placed a command in the wix-sorage, let it be just a simple key-word like → “redirect” and perhaps you even places a second one → “URL where to go to” inside the wix-storage (local or session and do not know which one will be the best one), you can simply navigate where ever you want → AFTER a LOGOUT.

How?

You just take your placed keywords out of the wix-storage again and use them to generate a CODE which starts right after page is READY, to navigate the user to another site → exactly the sites URL which was placed before logging out in the wix-storage.

I am not sure if there are more simple ways to achieve this. But this could be one possible way out.

https://www.wix.com/velo/reference/wix-storage

Ok, now i need to go to bed, already very very late. Just 2 hours remaining for sleep xD. See you next time! :sweat_smile::wink:

@russian-dima Ok, here’s the story.

Using the log-out code, it takes one back to the log-in screen … which is fine. You’re right, there is no way of redirecting after, or before, logging out. It’s either one or the other.

I’ve learned a lot … thanks to you … and solved my problem.

I wish I could do more for you … but times have been tough … I will send you a small thank you for your effort.

Best wishes … until we meet again.

Good morning! I have to say THANK YOU, too.

I am happy that i could help you out of your problem and your support is of course very appreciated, MERCI!