Is there an easy way to redirect users back to a specific page upon logout? Right now, I use the following:
$(document).on("knack-view-render.view_****", function (event, view, data) { // Login Page to Redirect
window.location.replace("**destination**"); // Destination Page
});
This works, but I have to have this full code for each and every login page. Is there another option I can use that will allow me to not have to repeat this over and over again?
/* Change the scene_1 to the scene key of your choice, or replace with any to work on all pages. */
$(document).on(‘knack-scene-render.scene_#’, function(event, scene, data) {
$(“a.kn-log-out”).on(“click”, function() {
// Some browsers need some wait-time to finish the logout
setTimeout(function(){
// replace with your desired URL
window.location = “URL-GOES-HERE”;
}, 500);
})
});
Thanks @Pieter, I’m sure that works, but that would be about the same as what I am using now. I was hoping there was a way to do this without having to have to repeat that code over and over again for every separate log in page.
Sunny, Thank you! This works perfectly. I really appreciate it.
One note: I removed the “console.log(Knack.getUserAttributes().id);” part. It works just fine without it. I took it out because it writes “undefined” to the console log, which allows for an easy one-click to see the entire .js file.
Hi @Sunny_Singla. I just came across an unexpected, minor issue with this: it works a little too well… Is there any way to exclude a specific view? The issue we are now having is that the reset password view redirects as well. So, if someone needs their password reset, and I do that from the builder, they cannot change their password because the reset password page will redirect them back to home.
Any suggestions? It’s not the end of the world, I normally manually change their passwords and just let them change it after login, but I was curious if there was a way to exclude a view.
I did not realize that the password reset page does not have a view number (at least not one that I can find). Since it does have a scene, I changed everything to knack-scene-render.any, and the view.key to scene.key and everything works great. Thank you again.
Hi Sunny, it is not working for me due to i also have “public pages” and when i run the app to the public pages, it goes to the login.
I have tried with your suggestion excluding view but without success. ( if (view.key!=“view_xyz”){} )
Have you any suggestions for my case? or may be, could you show me exactly where should i include the “if” to exclude a view.
In this case, you need to add multiple scene IDs in the array (which are public pages). and check if that scene id does not exist and id= undefined. then redirect. just an extra check of public scenes ids. for any professional help, you can also email me