Skip to content
Snippets Groups Projects
Commit ab1d5694 authored by Nabilsenko's avatar Nabilsenko
Browse files

fix: fixed hash

parent 413a8ecf
No related branches found
No related tags found
1 merge request!10Password haching
......@@ -15,7 +15,7 @@ import { JwtStrategy } from './jwt.strategy';
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '3600s' },
signOptions: { expiresIn: '300s' },
}),
],
controllers: [LoginController],
......
......@@ -25,21 +25,23 @@ export class PeopleDao {
private readonly _peopleModel: Model<People>,
) {}
login = async (email: string, password: string): Promise<People | void> => {
try {
const user = await this._peopleModel.findOne({ email });
if (!user) {
throw new NotFoundException('Email or password is incorrect!');
}
const isPasswordCorrect = await bcrypt.compare(password, user.passwordHash);
if (!isPasswordCorrect) {
throw new NotFoundException('Email or password is incorrect!');
}
return user;
} catch (error) {
throw error;
}
};
login = (email: string, password: string): Promise<People | void> =>
new Promise(async (resolve, reject) => {
this._peopleModel.findOne({ email: email }, async (err, value) => {
if (err) reject(err.message);
if (!value)
reject(new NotFoundException('Email or password is incorrect!'));
const isPasswordCorrect = await bcrypt.compare(
password,
value.passwordHash,
);
if (!isPasswordCorrect) {
reject(new NotFoundException('Email or password is incorrect!'));
}
value.passwordHash = password
resolve(value);
});
});
find = (): Promise<People[]> =>
new Promise((resolve, reject) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment