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

Redirect Doesnt Work Correctly #1032

Closed
mahiraltinkaya opened this issue Jan 26, 2021 · 3 comments
Closed

Redirect Doesnt Work Correctly #1032

mahiraltinkaya opened this issue Jan 26, 2021 · 3 comments
Labels

Comments

@mahiraltinkaya
Copy link

Hello friends;

I ran into a problem with Nuxt auth on the redirect process.

I shared my auth-guard and configurations below.

My expectation is that the page I use auth-guard middleware will be directed to the login page if I am not logged in, and then go to the page I want to enter after login. But after login it is always redirected to the homepage. Can you help me?

loggedIn == false auth-guard redirected me this page
http://localhost:3000/uye-girisi?redirect=%2FSiparislerim

after login redirect me and redirect main page "/"
http://localhost:3000/?redirect=%2FSiparislerim

Auth-guard MW

export default async function({ $auth, redirect, store, route }) {
  if (!$auth.loggedIn) {
    redirect(`/uye-girisi?redirect=${route.path}`);
  }
}

Nuxt.config

 auth: {
    rewriteRedirects: true,
    fullPathRedirect: true,
    redirect: {
      login: "/uye-girisi",
      logout: "/"
    },
    strategies: {
      local: {
        token: {
          property: "token",
          type: "Bearer"
        },
        user: {
          property: "user"
        },
        endpoints: {
          login: { url: "/login", method: "post" },
          logout: { url: "/logout", method: "post" },
          user: { url: "/user", method: "get" }
        }
      }
    }
  },

-->

@teethgrinder
Copy link

teethgrinder commented Jan 26, 2021

I think you need to add call

redirect: {
      login: '/login',
      logout: '/login',
      callback: '/login',
      home: '/',
    },

ps: I have tried your code and it works like a charm.

@men232
Copy link

men232 commented Nov 17, 2021

I just noted one weird thing, $auth.loggedIn always false after loginWith calling. Try to initialize vuex with default auth state, like this:

// store/state.js

export default () => ({
  auth: {
    loggedIn: false,
  },
});

@bmulholland
Copy link
Contributor

#1010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants