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

How can you access this module from context.app in plugins? #11

Closed
Steve525 opened this issue Mar 14, 2018 · 3 comments
Closed

How can you access this module from context.app in plugins? #11

Steve525 opened this issue Mar 14, 2018 · 3 comments

Comments

@Steve525
Copy link

Steve525 commented Mar 14, 2018

I'm wondering if it's possible to access this module from the context.app object passed in on plugin initialization. Not seeing it present.

This question is available on Nuxt.js community (#c11)
@Alig96
Copy link

Alig96 commented Apr 2, 2018

I'm also not seeing it in the context. Need this so I can set my userId via middleware.

@jpsilva
Copy link

jpsilva commented Jul 10, 2018

This is what works for me:

import Vue from 'vue'

export default function setUserId({ app }: Context) {
  if (process.client) {
    if (app.$auth.loggedIn) {
      Vue.$ga.set('userId', app.$auth.user.id)
    } else {
      Vue.$ga.set('userId', null)
    }
  }
}

I haven't figured out how to set userId on page load, but this will set it when the user navigates to another page, including on log in and log out.

@mohammad-saadati
Copy link

mohammad-saadati commented Apr 24, 2020

i had the same problem and this is how it works
i wrote the below code in global-scripts.js file which is located inside of plugins directory:

export default function doSomeThingOnAppMounting(app) {
if (process.client) {
app.app.mounted = function() {
//do whatever you want to be executed in app root vue instance mounted life cycle
}
}
}

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

5 participants