0

我正在为应用程序构建身份验证(使用 bcrypt、jwt)——react/redux/webpack——我在将身份验证功能连接到我的登录容器(我想在下面运行功能的登录表单)时遇到问题身份验证文件并将用户发布到我们的数据库)。

当我尝试将我的身份验证代码(如下)中的登录功能(import { signin} from './Auth/controllers/authentication')导入我的登录容器时,我收到了一个令人讨厌的错误。我究竟做错了什么?如何在我的登录模式/屏幕中使用身份验证功能?

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)});
    });    

  });
}

这是登录代码:

import React, { Component } from 'react';
import { render } from 'react-dom';
import { Button, Modal } from 'react-bootstrap';

import { signin } from './Auth/controllers/authentication';


export default class Login extends Component {

  render() {

    const { openLogin, closeLogin, login } = this.props;

    return (
      <div>
        <div className="login-corner">
         <span className="login" onClick={openLogin}>LOGIN</span> 
        </div>
          <Modal className="modal-dialog" bsSize="small" show={login.login} closeTimeoutMS={150}>
            <Modal.Body>
            <Modal.Title className="login-title">Login</Modal.Title>
            </Modal.Body>
            <div className="login-input">
              <div className="form-group">
                <div className="user-input">
                  <i className="glyphicon glyphicon-user"></i>
                  <input type="email" className="form-control" placeholder="Username"/>
                </div>
                <div className="password-input">
                  <i className="glyphicon glyphicon-lock"></i>
                  <input type="password" className="form-control" placeholder="Password"/>
                </div>
              </div>
            </div>
            <div className="login-button">
              <Button className="btn btn-info" onClick={closeLogin}>Welcome Back!</Button>
            </div>
            <div className="register-button">
              <a className="register-link" ui-sref="register" onClick={closeLogin}>Not a member? Sign up!</a> 
            </div>
          </Modal>
      </div>
    );
  }
}
4

1 回答 1

0

bcrypt-nodejs 的 repo 似乎不再维护。建议的替换是bcrypt

于 2016-04-12T05:39:31.813 回答