我正在为应用程序构建身份验证(使用bcrypt,jwt) - react / redux / webpack - 我在将我的身份验证功能连接到我的登录容器时遇到问题(我希望运行这些功能的登录表单在下面的身份验证文件中并将用户发布到我们的数据库)。
当我尝试从我的身份验证代码(下面)导入登录功能(从' ./ Auth / controllers / authentication'中导入{signin})到我的登录容器时,我收到了一个令人讨厌的错误。我究竟做错了什么?如何在登录模式/屏幕中使用身份验证功能?
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.stat_btn:
someFunction();
//you can also call Log or Toast here
break;
case R.id.comment_btn:
someFunction2();
break;
case R.id.forward_btn:
someFunction3();
break;
}
}
这就是错误之一,现在这里是代码(下面的身份验证,以及登录模式):
ERROR in ./~/bcrypt-nodejs/bCrypt.js
Module parse failed: /Users/myname/Desktop/SaltyEndzone/node_modules/babel-loader/index.js?{"presets":["es2015","react"]}!/Users/myname/Desktop/groupname/node_modules/bcrypt-nodejs/bCrypt.js Line 293: Octal literals are not allowed in strict mode.
You may need an appropriate loader to handle this file type.
| rounds = r1 + r2;
| real_salt = salt.substring(off + 3, off + 25);
| password = password + (minor >= 'a' ? "\000" : "");
|
| var buf = new Buffer(password);
@ ./public/Login/Auth/models/user.js 6:13-37
这是登录代码:
//authentication.js
const jwt = require('jwt-simple');
const config = require('../config');
const User = require('../models/user');
function tokenForUser(user) {
const timestamp = new Date().getTime();
return jwt.encode({ sub: user.id, iat: timestamp }, config.secret);
}
exports.signin = function(req, res, next) {
res.send( {token: tokenForUser(req.user)} );
}
exports.signup = function(req, res, next) {
const email = req.body.email;
const password = req.body.password;
if (!email || !password) {
return res.status(422).send({error: 'You must provide email and password'});
}
User.findOne( {email: email }, function(err, existingUser) {
if(err) {
return next(err);
}
if (existingUser) {
return res.status(422).send({error: 'Email is in use'})
}
const user = new User({
email: email,
password: password
});
user.save(function(err){
if(err) {
return next(err);
}
res.json({token: tokenForUser(user)});
});
});
}