所以我在firebase简单身份验证方面遇到了最奇怪的问题......
当我访问时localhost/#register
,填写表格,然后提交,我SERVER_ERROR
在authClient.createUser()
回调中得到一个。但是当我刷新页面并再次填写表格时,它可以工作了!
每次我重新启动服务器并尝试注册用户时,都会发生这种情况。
重申一下,我第一次执行它时出现服务器错误,但在我刷新页面后,一切都像魅力一样......这让我认为我错误地包含了 firebase 脚本,并且所有必要的文件都没有直到刷新才被包括在内,但我看不出哪里出错了。
更新:提交表单时出现此错误(出于隐私考虑):
WebSocket connection to 'wss://s-demo.firebaseio-demo.com/.ws?**********************' failed: WebSocket is closed before the connection is established.
错误来自firebase.js
第 51 - 63 行。
Stack - brunch.io 与骨干木偶。基本上它是一个 gruntJS 构建,带有咖啡脚本和一个 commonJS 包装器,用于非常简单的前端模块化。
index.html - 我在其中包含脚本
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Brunch with Marionette</title>
<meta name="viewport" content="width=device-width">
<!-- CSS and font-awesome -->
<link rel="stylesheet" href="stylesheets/app.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.css" rel="stylesheet">
<!-- Grunt compiled scripts -->
<script src="javascripts/vendor.js"></script>
<script src="javascripts/app.js"></script>
<!-- Firebase scripts -->
<script src="javascripts/backbone-firebase.js"></script>
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script type='text/javascript' src='https://cdn.firebase.com/v0/firebase-auth-client.js'></script>
<!-- Start application -->
<script>
require('initialize');
</script>
</head>
<body>
</body>
</html>
RegisterView.coffee - 我创建 authClient 并尝试创建一个新的 firebase 注册用户(主干模型被UserList
正确添加到集合中,然后与数据库正确同步,唯一的问题是createUser()
)
template = require './templates/register'
User = require '../models/user'
user = new User()
module.exports = class RegisterView extends Backbone.Marionette.ItemView
id: 'register-view'
template: template
model: user
initialize: ->
this.form = $(this.el).find('form#account')
base = new Firebase("https://***********.firebaseIO-demo.com/")
this.authClient = new FirebaseAuthClient base,
(error, user_cb)->
if (error)
console.log(error)
else if (user_cb)
console.log('User ID: ' + user_cd.id + ', Provider: ' + user_cb.provider)
else
# This is currently what gets executed,
# which I'm pretty sure is correct behavior
console.log('logged out')
events:
'submit form': 'on_submit'
'blur #first_name' : 'check_first'
'blur #last_name' : 'check_last'
'blur #email' : 'check_email'
'blur #password' : 'check_password'
'blur #confirm_password' : 'check_confirm_password'
on_submit: (e)->
this.add_user()
check_first: (e)->
check_last: (e)->
check_email: (e)->
check_password: (e)->
check_confirm_password: (e)->
add_user: (e)->
form = $(this.el).find('form#account')
user.set({
first_name : form.find('#first_name').val()
last_name : form.find('#last_name').val()
email : form.find('#email').val()
password: form.find('#password').val()
})
window.UserList.add(user)
email = form.find('#email').val()
password = form.find('#password').val()
this.authClient.createUser(email, password,
(error, user)->
if (error)
console.log(error)
if (!error)
console.log('User Id: ' + user.id + ', Email: ' + user.email)
)
更新:我尝试将服务器从生产服务器更改-demo
为生产服务器,但没有任何区别。