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

fix(auth): add path helper function #235

Merged
merged 2 commits into from
Sep 7, 2018
Merged

Conversation

sghgh1996
Copy link

In middleware.js file it checks for login route to redirect:

if (!login || ctx.route.path === login.split('?')[0]) {
      ctx.app.$auth.redirect('home')
}

the login is const { login, callback } = ctx.app.$auth.options.redirect so it is constant.
for example /login. In if condition it should split ctx.route.path and then checks it with login.
And there is another problem. In some cases the login route path is /login/. So I added a helper function
and it splits the path and remove / from the path.
the function:

const splitPath = path => {
    // remove query string
    let result = path.split('?')[0]
    // remove redundant / from the end of path
    if (result.charAt(result.length - 1) === '/') {
      result = result.slice(0, -1)
    }
    return result
}

new if condition:

if (!login || ctx.route.path === login.split('?')[0]) {
      ctx.app.$auth.redirect('home')
}

@sghgh1996 sghgh1996 changed the title fix(auth): add split helper function fix(auth): add path helper function Sep 5, 2018
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@pi0 pi0 merged commit 398a515 into nuxt-community:dev Sep 7, 2018
@pi0 pi0 mentioned this pull request May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants