首页 > 解决方案 > Pyrebase 认证不返回成功案例

问题描述

您好,我正在使用烧瓶制作 Web 应用程序,并尝试通过 pyrebase 实现 Firebase 身份验证,但无法成功登录。我似乎无法auth.sign_in_with_email_and_password(email, password)上班。

@app.route('/login', methods=['GET', 'POST'])
def login():
    unsuccessful = 'Please check your credentials'
    successful = 'Login successful'
    form=LoginForm()
    if request.method == 'POST':
        password = form.password.data
        email = form.email.data
        print(email)
        print(password)
        try:
            user = auth.sign_in_with_email_and_password(email, password)
            print(user)
            return render_template('login.html', s=successful,form=form)
        except KeyError:
            return render_template('donation.html')
        except:
            return render_template('login.html', us=unsuccessful,form=form)
    return render_template('login.html',form=form)

它总是以这种情况告终return render_template('login.html', us=unsuccessful,form=form)

这是我的形式课。

class LoginForm(FlaskForm):
    email = StringField('Email', validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired()])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')

这是 login.html。

{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}

{% if s %}
    <div class="alert alert-success">
        <h2>{{s}}</h2>
    </div>
{% endif %}

{% if us %}
    <div class="alert alert-danger">
        <h2>{{us}}</h2>
    </div>
{% endif %}

<h1>Sign In</h1>
<div class="row">
    <div class="col-md-4">
        {{wtf.quick_form(form)}}
    </div>
</div>
{% endblock %}

标签: firebaseflaskflask-wtformspyrebase

解决方案


我的 pyrebase/auth 初始化位于与我的路由不同的文件中。我放

firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()

连同与我的路由相同的文件中的firebase配置,我获得了成功的身份验证。


推荐阅读