Jump to content

Log-Out shortcut link for RockFrontend topbar


Stefanowitsch
 Share

Recommended Posts

I was in the need to add a "log-out" shortcut to the RockFrontend topbar. 

The motivation behind this is that I am using @bernhard's RockPageBuilder module and when you are logged in and do some frontend-editing you want to have a quick look on the page without the RockPageBuilder markup (all the edit-icons, etc.) . You just want to check how the the page looks like to the user.

Yeah, you coooould open the page on a separate browser but I like this solution:

In the topbar.php file in the RockFrontend module folder go to line 58 and append this code:

<a href="<?=$config->urls->admin?>login/logout/">
    <svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M502.6 278.6C515.1 266.1 515.1 245.8 502.6 233.3L374.6 105.3C362.1 92.8 341.8 92.8 329.3 105.3C316.8 117.8 316.8 138.1 329.3 150.6L402.7 224H192C174.3 224 160 238.3 160 256C160 273.7 174.3 288 192 288H402.7L329.3 361.4C316.8 373.9 316.8 394.2 329.3 406.7C341.8 419.2 362.1 419.2 374.6 406.7L502.6 278.7V278.6ZM160 96C177.7 96 192 81.7 192 64C192 46.3 177.7 32 160 32H96C43 32 0 75 0 128V384C0 437 43 480 96 480H160C177.7 480 192 465.7 192 448C192 430.3 177.7 416 160 416H96C78.3 416 64 401.7 64 384V128C64 110.3 78.3 96 96 96H160Z" fill="black"/>
    </svg>
  </a>

This will render a new "log-out" button in the top bar:

image.png.c2e0721c1212d9a400d9635bad849757.png

I just inserted a random svg code here, so the styling does not 100% fit the look of the other icons.

After clicking you will be logged out and redirected to the login-mask.

BUT:

What I want to achieve was:

"Log me out but instead of redirecting me to the login mask, I want to stay on the same page that I logged out from!"

1. We alter the code from above to include a redirect parameter that includes the current page URL:

<a href="<?=$config->urls->admin?>login/logout/?redirect=<?=urlencode($page->url)?>">
  <svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M502.6 278.6C515.1 266.1 515.1 245.8 502.6 233.3L374.6 105.3C362.1 92.8 341.8 92.8 329.3 105.3C316.8 117.8 316.8 138.1 329.3 150.6L402.7 224H192C174.3 224 160 238.3 160 256C160 273.7 174.3 288 192 288H402.7L329.3 361.4C316.8 373.9 316.8 394.2 329.3 406.7C341.8 419.2 362.1 419.2 374.6 406.7L502.6 278.7V278.6ZM160 96C177.7 96 192 81.7 192 64C192 46.3 177.7 32 160 32H96C43 32 0 75 0 128V384C0 437 43 480 96 480H160C177.7 480 192 465.7 192 448C192 430.3 177.7 416 160 416H96C78.3 416 64 401.7 64 384V128C64 110.3 78.3 96 96 96H160Z" fill="black"/>
  </svg>
</a>

2. For the redirect you have to put this hook function inside your ready.php file:

$wire->addHookBefore("ProcessLogin::executeLogout", null, "setRedirect");

function setRedirect(HookEvent $event) {
    $input = wire('input');

    // Check if the 'redirect' query parameter is present
    if ($input->get->redirect) {
        // Get the redirect URL from the query parameter
        $redirectURL = $input->get->redirect;

        // Set the logout URL to the specified redirect URL
        $event->object->setLogoutURL($redirectURL);
    }
}

After doing that the log-out button will log you out BUT keep you staying on the same page.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...