Hi guys! I’m very new to Knack and would appreciate some help here.
The app has multiple roles ( multiple protected pages ), I’ve used a “General Login“ (/login) so that users can go through one login page and be redirected based on their role.
But when logging out, I’m sent back to the login page of that page (e.g /role-dashboard-login) rather than going back to the general login. Oh and I can’t find where to do custom JS (only CSS) and as comfortable as I am with JS, I’d love to keep it within Knack unless really necessary.
What you’re running into depends on whether your app is built in Classic or the new Next Gen version. Given the fact that you’re missing the JavaScript section I think you’re on Next Gen.
Next Gen (the new React version): At the moment, only custom CSS is supported – no JavaScript yet. That means it isn’t possible right now to override the logout redirect to always go back to your General Login page.
Classic (the existing jQuery version): This is possible. With a little bit of custom JavaScript, you can catch the logout action and send users back to /login instead of the role-specific login page.
If you were on Classic, (according to my good friend, ChatGPT ), you could do something like this. I’m sure you know better than me.
$(document).on('knack-scene-render.any', function(event, scene) {
$('a.kn-log-out').off('click').on('click', function(e) {
e.preventDefault();
Knack.logout();
window.location.href = '/login'; // Always go back to General Login
});
});
If you’re on Next Gen, this isn’t possible yet – Knack are currently working on introducing JavaScript.