小编tes*_*eam的帖子

错误:React JS 中的请求失败,状态码为 401 axios

我正在使用 Laravel API 和 ReactJS 前端创建登录页面。我在 ReactJS 中使用Axios来解析username(email)password。登录 APIhttp://127.0.0.1:8000/api/login在 postman 中正常工作form-data。但是当我进入emailpassword反应前端时,回声是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)

javascript reactjs axios

6
推荐指数
2
解决办法
4万
查看次数

使用 JWT 进行护照身份验证:如何将护照的默认未授权响应更改为我的自定义响应?

Nodepassport. 当我没有将令牌作为标头提供时,它返回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)

authentication node.js jwt passport.js passport-jwt

5
推荐指数
1
解决办法
3647
查看次数

Zoho 邮件显示 Node Js 中的 535 身份验证失败

我正在使用 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)

zoho node.js nodemailer

4
推荐指数
1
解决办法
2314
查看次数

与 React Js 同时使用 npm

我有一个使用 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)

npm concurrently

2
推荐指数
1
解决办法
9458
查看次数