I am trying to deploy a site to firebase, with dynamic content being served by Cloud Run via Flask. I am using the flask-login package, and this is working fine locally, when using firebase serve, and it also works perfectly when visitng the Cloud Run app (the stylesheet and other static content are obviously missing).
However, when visiting the firebase site the static content is served, although the login page returns a 401 unauthorized error when logging in.
login.html:
<div class="box">
<h1>Login</h1>
<form method="post">
<input type="text" name="email" placeholder="Email" required="required"/>
<input type="password" name="password" placeholder="Password" required="required"/>
<button type="submit" class="btn btn-primary btn-block btn-large">Login</button>
</form>
</div>
app.py:
@app.route('/login', methods=["GET", "POST"])
def login():
if request.method == "POST":
email = request.form.get('email')
password = request.form.get('password')
# Email doesn't exist or password incorrect.
if user.get_id() == email:
flash("That email does not exist, please try again.")
return redirect(url_for('login'))
elif not password == 'xxx':
flash('Password incorrect, please try again.')
return redirect(url_for('login'))
else:
login_user(user)
return redirect(url_for('secrets'))
return render_template("login.html", logged_in=user.is_authenticated)
@app.route('/secrets')
@login_required
def secrets():
print(user.name)
return render_template("secrets.html",
name=user.name,
logged_in=user.is_authenticated,
latest_weight=latest_weight(),
)
I am not sure if code will help in this case, I think I must have misunderstood something about the session information is being handled by flask-login. I can't recreate the error outside of the firebase/cloud run environment, so it's quite hard to troubleshoot.
Cloud run logs don't provide any useful information other than a GET request returned a 401.