title: current_user changing value in flask
body: <p>I am new to flask so please forgive me if my code is lousy and try to give corrections.
  I am trying to implement a login using flask-login in my app. When I login <code>current_user</code> is shown as <code>&lt;user "nickname"&gt;</code>, but after a refresh it shows as anonymous.</p>
  
  <p>Here is what I think is the relevant code in my views file.</p>
  
  <pre><code>@app.route('/login', methods=['GET', 'POST'])
  def login():
      form = LoginForm()
      if form.validate_on_submit():
          user = User.query.filter_by(email=form.email.data).first()
          if form.validate_on_submit():       
              if user is None:
                  user = User(name=form.name.data,email=form.email.data,password=form.password.data) 
                  db.session.add(user)
                  db.session.commit()
                  login_user(user,remember=True)
                  return redirect(url_for('index'))
              else:
                  user=User(name=form.name.data,password=form.password.data,email=form.email.data)
                  if True #eventually this will check whether the password you inputted matches the password associated with the email you inputted:
                      login_user(user,remember=True)
      return render_template('login.html', form=form,)
  
  @app.route("/logout")
  @login_required
  def logout():
      logout_user()
      return redirect(url_for("index"))
  
  @app.before_request
  def before_request():
      g.user = current_user 
  </code></pre>
  
  <p>I've had a good search for the answer so I think the problem is with my system for logging in users not actually the <code>current_user</code>.
  Thanks in advance</p>
  
  <p>EDIT:
  The problem turned out to be that my <code>get_id</code> function was returning <code>self.id</code>, which did not exist. I made it return <code>self.email</code>, and all was fine.</p>