fixes bug with password auth
This commit is contained in:
@@ -15,7 +15,6 @@ import Edit from './views/collections/Edit';
|
||||
import EditGlobal from './views/Global';
|
||||
import { requests } from '../api';
|
||||
import customComponents from './customComponents';
|
||||
import RedirectToLogin from './utilities/RedirectToLogin';
|
||||
import ResetPassword from './views/ResetPassword';
|
||||
import Unauthorized from './views/Unauthorized';
|
||||
import Loading from './elements/Loading';
|
||||
|
||||
10
src/errors/AuthenticationError.js
Normal file
10
src/errors/AuthenticationError.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const httpStatus = require('http-status');
|
||||
const APIError = require('./APIError');
|
||||
|
||||
class AuthenticationError extends APIError {
|
||||
constructor() {
|
||||
super('The username or password provided is incorrect.', httpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuthenticationError;
|
||||
@@ -1,4 +1,5 @@
|
||||
const APIError = require('./APIError');
|
||||
const AuthenticationError = require('./AuthenticationError');
|
||||
const DuplicateCollection = require('./DuplicateCollection');
|
||||
const DuplicateGlobal = require('./DuplicateGlobal');
|
||||
const MissingCollectionLabel = require('./MissingCollectionLabel');
|
||||
@@ -11,6 +12,7 @@ const MissingFile = require('./MissingFile');
|
||||
|
||||
module.exports = {
|
||||
APIError,
|
||||
AuthenticationError,
|
||||
DuplicateCollection,
|
||||
DuplicateGlobal,
|
||||
MissingCollectionLabel,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const mongoose = require('mongoose');
|
||||
const passport = require('passport');
|
||||
const AnonymousStrategy = require('passport-anonymous');
|
||||
const LocalStrategy = require('passport-local').Strategy;
|
||||
const passportLocalMongoose = require('passport-local-mongoose');
|
||||
const jwtStrategy = require('./strategies/jwt');
|
||||
const apiKeyStrategy = require('./strategies/apiKey');
|
||||
@@ -20,6 +21,7 @@ function initUser() {
|
||||
Model: mongoose.model(this.config.User.slug, userSchema),
|
||||
};
|
||||
|
||||
passport.use(new LocalStrategy(this.User.Model.authenticate()));
|
||||
passport.use(this.User.Model.createStrategy());
|
||||
passport.use(apiKeyStrategy(this.User));
|
||||
passport.use(jwtStrategy(this.User));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { Forbidden } = require('../../errors');
|
||||
const { Forbidden, AuthenticationError } = require('../../errors');
|
||||
|
||||
const login = async (args) => {
|
||||
try {
|
||||
@@ -35,7 +35,11 @@ const login = async (args) => {
|
||||
|
||||
if (!user) throw new Forbidden();
|
||||
|
||||
await user.authenticate(password);
|
||||
const authResult = await user.authenticate(password);
|
||||
|
||||
if (!authResult.user) {
|
||||
throw new AuthenticationError();
|
||||
}
|
||||
|
||||
const fieldsToSign = config.fields.reduce((signedFields, field) => {
|
||||
if (field.saveToJWT) {
|
||||
|
||||
Reference in New Issue
Block a user