title: How to access flask auth token from a different blueprint
body: <p>I have a flask app with 2 blueprints. auth blueprint and events blueprint. This is how they are structured</p>
  
  <pre><code>`app/
      auth_blueprint/
              init.py
              views.py
              model.py
      events_blueprint/
              init.py
              model.py
              views.py 
  `
  </code></pre>
  
  <p>auth_blueprint handles user events. login,registration etc. My question is, how do I access a token generated from auth_blueprint upon login and use it in the events_blueprint to secure the other endpoints?</p>
  
  <p>in views under auth_blueprint the authentication code is</p>
  
  <pre><code>@authenticate.verify_password
  def verify_password(username_or_token, password):
      # first try to authenticate by token
      user = models.User.verify_auth_token(username_or_token)
      if not user:
          # try to authenticate with username/password
          user = models.User.query.filter_by(username = username_or_token).first()
          if not user or not user.verify_password(password):
              return False
      g.user = user
  
      import pdb; pdb.set_trace() #debugger
      return True
  
  #login user
  @auth.route('/api/v1/auth/login')
  @authenticate.login_required
  def login():    
      token = g.user.generate_auth_token()
      return jsonify({ 'token': token.decode('ascii') })
      #return jsonify({'Welcome':'Login Okay'}),200 
  </code></pre>
  
  <p>When I try to access g in views under events_blueprint i get an error g has no attribute user</p>
  
  <pre><code>@events.route('/api/v1/user')
  def getloggeduser():
      print(g)
      import pdb; pdb.set_trace()
      return g
  </code></pre>
  
  <p>PS: that is for testing purpose. I am only interested in getting user object stored in g and later on retrieve a userid from there.</p>
  
  <p>I am using jwt for token based authentication. Let me know if anything needs clarification. Thank you</p>