firebase - 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 %}
解决方案
我的 pyrebase/auth 初始化位于与我的路由不同的文件中。我放
firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()
连同与我的路由相同的文件中的firebase配置,我获得了成功的身份验证。
推荐阅读
- python - pandas matrix calculation till the diagonal
- android - Flutter Release Apk Display black screen Issue on Startup
- ios - Json 解码为具有动态值类/结构类型的 swift 类
- nginx - Hostname (SNI) missing while using nginx ingress SSL Passtrough to underlying service
- r - 从R中数字向量的每个元素中提取第一个数字
- python - CMake:检查 Python3 和 Python 包的存在
- .net - 使用 serilog 时,我应该在生产中将日志写入什么?
- c# - Unity - 两秒钟后加载场景
- postgresql - 表内的 Postgresql 数据库备份
- firebase - 使用 Firebase 安全规则、自定义域和 CloudFlare 的静态托管 Google Cloud Storage