我正在使用 Laravel API 和 ReactJS 前端创建登录页面。我在 ReactJS 中使用Axios来解析username(email)和password。登录 APIhttp://127.0.0.1:8000/api/login在 postman 中正常工作form-data。但是当我进入email和password反应前端时,回声是Error: Request failed with status code 401.axios 的 catch 函数抛出的这个错误。我也在使用查询字符串npm。那么哪个会抛出这个错误?
我的 React JS 代码
import React, { Component } from 'react';
import { Button, Card, CardBody, CardGroup, Col, Container, Input, InputGroup, InputGroupAddon, InputGroupText, Row } from 'reactstrap';
import axios from 'axios';
import { Redirect } from 'react-router-dom'
import querystring from 'querystring';
class …Run Code Online (Sandbox Code Playgroud) 我Node用passport. 当我没有将令牌作为标头提供时,它返回Unauthorized. 我怎样才能将此消息更改为漂亮的Sorry invalid credentials
每次无法提供令牌时,我都会收到未授权的响应。我想把它改成漂亮的消息。
护照.js
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const mongoose = require('mongoose');
var User = require('../models/user'); // get the mongoose model
const keys = require('../config/keys');
const opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = keys.secretOrKey;
module.exports = passport => {
passport.use(
new JwtStrategy(opts, (jwt_payload, done) => {
User.findById(jwt_payload.id)
.then(user => {
if (user) {
return done(null, user);
}
return done(null, false);
})
.catch(err => console.log(err))
}) …Run Code Online (Sandbox Code Playgroud) 我正在使用 Node Express 和 MongoDB 创建一个应用程序。用户创建成功后,想要发送给用户的邮件。我正在使用 zohomail,可以使用这些用户名和密码在线登录 zohomail。但是当我尝试发送邮件时出现错误
code: 'EAUTH',
response: '535 Authentication Failed',
responseCode: 535,
command: 'AUTH PLAIN'
Run Code Online (Sandbox Code Playgroud)
这是我的代码
if (user) {
var transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'sample@sample.com', //zoho username
pass: 'password' //zoho password## Heading ##
}
});
var mailOptions = {
from: 'sample@sample.com',
to: req.body.email,
subject: 'Created Successfully',
html: '<h1>Hi ' + req.body.fname + ',</h1><p>You have successfully created.</p>'
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) { …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Node express 和 React Js 创建的项目。服务器(节点)package.json如下。它同时使用npm run dev. 服务器使用端口5000,客户端使用端口3000,文件夹结构如下。
/
|
|-mysample
|
|-client
| |-.env
| |-package.json
| |-src
|-server.js
|-package.json
Run Code Online (Sandbox Code Playgroud)
package.json(mysample)
{
"name": "mysample",
"version": "1.0.0",
"description": "My Sample",
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "nodemon server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "test",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": …Run Code Online (Sandbox Code Playgroud) node.js ×2
axios ×1
concurrently ×1
javascript ×1
jwt ×1
nodemailer ×1
npm ×1
passport-jwt ×1
passport.js ×1
reactjs ×1
zoho ×1