我已经使用jwt处理了数据,然后将使用passwordjs进行bcrypt进行身份验证。
但是,当执行passportjs时,所有内容都会变得未经授权
我不知道为什么,对不起,我是新来的。
我的路线
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#define report_error(x) puts("error")
#define BUFFER_SIZE 1<<16
int main(int argc, char *argv[])
{
struct stat statbuf1;
struct stat statbuf2;
char *fn1;
char *fn2;
if (argc < 3) {
if (argc < 1) {
report_error("no command line");
} else {
report_error("Not enough arguments");
}
}
fn1 = argv[1];
fn2 = argv[2];
if (lstat(fn1, &statbuf1)) {
report_error(strerror(errno));
}
if (lstat(fn2, &statbuf2)) {
report_error(strerror(errno));
}
if (S_ISCHR(statbuf1.st_mode) && S_ISCHR(statbuf2.st_mode)) {
unsigned int major1 = major(statbuf1.st_dev);
unsigned int major2 = major(statbuf2.st_dev);
unsigned int minor1 = minor(statbuf1.st_dev);
unsigned int minor2 = minor(statbuf2.st_dev);
printf("%d %d\n%d %d\n", major1, major2, minor1, minor2);
if (major1 == major2 && minor1 == minor2) {
printf("the two device files are equal\n");
exit(0);
}
}
return 0;
}
对于控制器,我以登录示例为例
const express = require('express');
const router = require('express-promise-router')();
const passport = require('passport');
const passportConf = require('../passport');
const { validateBody, schemas } = require('../helpers/routeHelpers');
const adminController = require('../controllers/admin');
const passportSignIn = passport.authenticate("jwt", {
session: false,
failWithError: true
});
const passportJWT = passport.authenticate('local', { session: false, failWithError: true });
router.route('/signup')
.post(validateBody(schemas.authSchema), adminController.signUp);
router.route('/signin')
.post(
// validateBody(schemas.authSchema),
passportSignIn,
adminController.signIn
);
router.route('/secret')
.get(
passportJWT,
adminController.secret);
module.exports = router;
错误消息:
const JWT = require('jsonwebtoken');
const Admin = require('../models/admin');
const { JWT_SECRET } = require('../configuration');
signToken = admin => {
return JWT.sign({
iss: 'NodeAPI',
sub: Admin.id,
iat: new Date().getTime(),
exp: new Date().setDate(new Date().getDate() + 1)
}, JWT_SECRET)
}
signIn : async (req, res, next) => {
//generate Token
const token = signToken(req.admin);
// res.status(200).json({ token })
console.log(token)
},
假设:我已经用邮递员来表示密码和电子邮件,非常感谢您的帮助,先生:)