python 我收到错误AttributeError:“Auth”对象在Flask应用程序中没有属性“get_user”

h5qlskok  于 2022-12-17  发布在  Python
关注(0)|答案(1)|浏览(114)
from firebase_admin import auth

@app.route("/admin/dashboard")
def admin_dashboard():
    current_user = auth.get_user(request.cookies.get("session"))
    # If the user is not authenticated, redirect to the login page
    if not current_user:
        return redirect(url_for('/admin/login'))
    return render_template("admin/dashboard.html")

我收到以下错误“当前用户= auth.get用户(请求. cookie.get(“会话”))属性错误:“Auth”对象没有属性“get_user”“

lvjbypge

lvjbypge1#

您需要在模块auth中使用类Client:

from firebase_admin import auth

@app.route("/admin/dashboard")
def admin_dashboard():
    current_user = auth.Client.get_user(request.cookies.get("session"))
    # If the user is not authenticated, redirect to the login page
    if not current_user:
        return redirect(url_for('/admin/login'))
    return render_template("admin/dashboard.html")

更多详细信息请参见here

相关问题