Auth-module: Add hook after loginWith using any social option

Created on 25 Apr 2018  路  3Comments  路  Source: nuxt-community/auth-module

What problem does this feature solve?

Hello,

Is there any ways to add a hook like a user logged in with social login then directly its data will be sent directly to store. What if I want to fetch the users data from backend server before setting it up to store.

What does the proposed changes look like?

Allow hook/callback in a loginWith promise to be used in social login.

This feature request is available on Nuxt.js community (#c115)
enhancement

Most helpful comment

I also need this feature.

All 3 comments

I also need this feature.

+1
What is the purpose of

this.$auth.$storage.watchState('loggedIn', (newValue) => {
      console.log('Logged in user:', newValue)
    })

This function never gets triggered no matter where I register this listener! I kept it in login.vue and also in default.vue layout file, but this function never gets triggered!

By adding a plugin auth.js as below:

export default ({ app }) => {
  // Only _actual_ login/outs (including resets) will be watched here.
  console.log('Registering watch state in plugin!')
  app.$auth.$storage.watchState('user', (userNew, userOld) => {
    alert('User has signed in here')
    console.log('User signed in:', userNew, userOld)
    if (userNew) {
      // Follow @nuxtjs/auth workflow.
      app.$auth.redirect('home')
    }
  })
}

and auth config in nuxt.config.js as:

  auth: {
    watchLoggedIn: true,
    watchUser: true,
    plugins: [
      { src: '~/plugins/auth', mode: 'client' }
    ],
....
....

I am able to see the console.log getting printed during logout. But during login, nothing gets printed. Is this because of the social login redirects? Is there any way I can tap into the social login after ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuwacker picture yuwacker  路  3Comments

DougHayward picture DougHayward  路  4Comments

weijinnx picture weijinnx  路  3Comments

sebmor picture sebmor  路  3Comments

ishitatsuyuki picture ishitatsuyuki  路  4Comments