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

this.$auth.loggedIn is always FALSE #999

Closed
jbiddulph opened this issue Jan 14, 2021 · 10 comments
Closed

this.$auth.loggedIn is always FALSE #999

jbiddulph opened this issue Jan 14, 2021 · 10 comments

Comments

@jbiddulph
Copy link

my this.$auth.loggedIn is always FALSE, please help!!!
I am logging in, getting a valid jwt token and getting user details back in the response!

here is my NUXT auth version:
"@nuxtjs/auth-next": "^5.0.0-1610115973.9fdaa66",

and here is my nuxt.config.js

export default {
  // Global page headers (https://go.nuxtjs.dev/config-head)
  head: {
    title: 'choosday',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: [
    '~assets/scss/tailwind.scss',
  ],

  // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
  ],

  // Auto import components (https://go.nuxtjs.dev/config-components)
  components: true,

  // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  buildModules: [
    // https://go.nuxtjs.dev/tailwindcss
    '@nuxtjs/vuetify',
    '@nuxtjs/tailwindcss',
  ],
  ssr: true,
  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/auth-next'
  ],
  axios: {
    baseURL: 'http://choosapi.test/api'
    // baseURL: 'http://movemeapi.test/api'
  },
  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    vendor: ['axios', 'vuetify']
  },
  auth: {
    strategies: {
      local: {
        token: {
          property: 'token',
          required: true,
          type: 'bearer'
        },
        user: {
          property: 'user',
          autoFetch: true
        },
        endpoints: {
          login: { url: 'auth/login', method: 'post', propertyName: 'token' },
          logout: { url: 'logout', method: 'get', propertyName: 'token' },
          user: { url: 'auth/profile', method: 'get', propertyName: 'false' },
        }
      }
    }
  },
}
@jbiddulph jbiddulph added the bug label Jan 14, 2021
@JoaoPedroAS51
Copy link
Collaborator

Hi @jbiddulph! Can you show me the login response and the user response?

@jbiddulph
Copy link
Author

Login

token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9jaG9vc2FwaS50ZXN0XC9hcGlcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNjEwNjQyOTc5LCJleHAiOjE2xxxxthis_is_my_bearer_token_OSwianRpIjoieUtXU0dJcVZrbDY5SzhvaCIsInN1YiI6MTEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.cQVf2Y0nUzPPkTb4mQl8YsoJLManqum-onMDEgOW7I8"
token_type: "bearer"
token_validity: 86400

User:

{"id":11,"name":"John Biddulph","email":"myemail@gmail.com","email_verified_at":null,"created_at":"2021-01-13T22:07:16.000000Z","updated_at":"2021-01-13T22:07:16.000000Z"}

@bmulholland
Copy link
Contributor

It's pretty hard to debug slowly and via an Issue discussion. Can you please do some debugging to figure out why it's not set? Here's a place to start: https://github.com/nuxt-community/auth-module/blob/dev/src/core/auth.ts#L301

@jbiddulph
Copy link
Author

I don't have auth.ts file and I'm not using state?!

@JoaoPedroAS51
Copy link
Collaborator

@jbiddulph I think the problem is misconfiguration when migrating from v4 to v5. I updated your config, let me know if it worked :)

  auth: {
    strategies: {
      local: {
        token: {
          property: 'token',
          required: true,
          type: 'Bearer'
        },
        user: {
          property: false, // here should be `false`, as you defined in user endpoint `propertyName`
          autoFetch: true
        },
        // `propertyName` in endpoint was depreacted
        endpoints: {
          login: { url: 'auth/login', method: 'post' },
          logout: { url: 'logout', method: 'get' },
          user: { url: 'auth/profile', method: 'get' },
        }
      }
    }
  },

@jbiddulph
Copy link
Author

That's amazing, thank you so much!

@JoaoPedroAS51
Copy link
Collaborator

I'm happy to know it worked! :)

@VRuzhentsov
Copy link

I had a more complex issue, and have success fixing that with the next steps:
nuxt.config.js

axios: {
  https: !isLocalMachine // I had a lot of not handled errors inside lib related to https
},
auth: {
  cookie: {
    secure:  !isLocalMachine
  },
  strategies: {
    sessionid: { // strategyName (scheme name)  === cookie name . -> Token._syncToken()
      scheme: "cookie", // should use that key, to call CookieScheme class
      cookie: {
        // my custom backend cookie name, you should migrate to such usage after nuxt-auth@^4 migration
        name: "auth._token.sessionid" 
      }
    }
  }
}

@kabaluyot
Copy link

Breaking change indeed ...

@Owura-Kwaku
Copy link

I'm having a duplicate of #999. The difference is that I'm using a cookie based authentication.
Here is my nuxt.config.js file

auth: {
strategies: {
google: {
clientId:
' 941383346878-q2j64498ic9hubn079hb2j5or49cjvg3.apps.googleusercontent.com'
},
facebook: {
endpoints: {
userInfo:
'https://graph.facebook.com/v6.0/me?fields=id,name,picture{url}'
},
clientId: '574492650390644',
scope: ['public_profile', 'email']
},
cookie: {
cookie: {
name: 'api-eskool'
},
endpoints: {
login: {
url: '/login',
method: 'post'
},
logout: {
url: '/login',
method: 'delete'
},
user: {
url: '/profile',
method: 'get'
}
}
}
}
},

axios: {
baseURL: 'https://api.myeskool.com/users'
}

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

No branches or pull requests

6 participants