Pyrebase身份验证未返回成功案例

时间:2020-08-03 23:02:10

标签: firebase flask flask-wtforms pyrebase

您好,我正在使用flask开发一个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 %}

1 个答案:

答案 0 :(得分:0)

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

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

在与路由相同的文件中加上firebase配置,并获得成功的身份验证。