Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite redirection loop with vue-router default mode "hash" #1

Open
rgrosjean opened this issue Jun 6, 2018 · 8 comments
Open

Infinite redirection loop with vue-router default mode "hash" #1

rgrosjean opened this issue Jun 6, 2018 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@rgrosjean
Copy link

Hi,
it's more a question that a real issue, because I'm not sure if I configured something wrong or if I missed something.
The plugin works great with vue and vue-router when it's configured to use the mode history. If the default mode "hash" is set, after completing login, the page is redirected indefinitely.
Do you have any clue?

Thanks!

@nlien
Copy link
Contributor

nlien commented Sep 15, 2018

Hi! Sorry for the really late reply.
I've noticed the same behaviour you describe, but I haven't figured out the cause of this.
My solution was to just go for the history mode. If you ever find a solution to this, I'll be really grateful for a PR.

@rgrosjean
Copy link
Author

Hi, no problem.
I did not find any other workaround as to use the history mode. There is something with the # in the query string. Probably because Keycloak use it to pass some parameter.

@neowinx
Copy link

neowinx commented Oct 4, 2018

I have this same problem, but it seems that it is not only with Vue.js, other frameworks suffer from this issue to as per

https://www.google.com.py/search?q=redirect_fragment&oq=redirect_fragment&aqs=chrome..69i57j69i60l3j0l2.295j0j7&sourceid=chrome&ie=UTF-8

I will use the history mode in the meantime

Good Luck!

@anderius anderius added the help wanted Extra attention is needed label Oct 11, 2018
@ChuckFields
Copy link

I've experienced this infinite redirect and I have a workaround to allow you to continue to use the default hash mode with the VueRouter. Take a look at how I initialize my vue app:

keycloak.init().success((authenticated) => {
  if (authenticated) {
    // The VueRouter plugin gets installed via Vue.use(VueRouter) inside of our ./router
    // We need to dynamically import our vue router here because otherwise it will install this plugin
    // before Keycloak is done and will cause an infinite redirect
    import('./router')
      .then((router) => {
        new Vue({
          el: '#app',
          router: router.default,
          store,
          render: h => h(App)
        });
      });
  }
});

Essentially, we need to wait until Keycloak is done doing its thing before installing the VueRouter plugin.

However, now i'm running into another (minor) issue.
If I do the following steps:

  1. login (I'm now at /#/dashboard)
  2. navigate to /#/admin
  3. wait for my access token to expire and fetch a new one
  4. logout

When I log back in I will end up at /#/dashboard instead if /#/admin
If however, I remove step 3 from above, I will end up back at /#/admin
I'm still trying to figure this one out.

@alfreema
Copy link

alfreema commented Jun 3, 2019

Is anybody actively working on a fix/work around for this issue?

@anderius
Copy link
Contributor

anderius commented Jun 3, 2019

No, but any help would be greatly appreciated!

@zg2pro
Copy link

zg2pro commented Sep 23, 2020

Hi all!

I also encountered this issue and found a workaround

(as delaying the vue-router like @ChuckFields didnt work for me): actually my router runs after the VueKeycloak init anyways but still it turned around and around and around on itself...

So, I switched from "login-required" to the "check-sso" mode, BUT, to be able to still get redirected to my keycloak interface, I put this in my router.js:

router.beforeEach((to, from, next) => {
  if (!router.app.$keycloak.authenticated) {
    window.location.replace(router.app.$keycloak.createLoginUrl());
  }
(...)
next();
}

@ch4dwick
Copy link

ch4dwick commented Apr 27, 2021

At the date of this writing I was able to fix this by enabling third-party cookies in Chrome & Safari and Shields Off for Brave. The checkLoginIframe:false checking false solution didn't fix it for me.

The issue doesn't affect MS Edge as of this writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Development

No branches or pull requests

8 participants