aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/DashUserModel.ts
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-05-05 18:28:35 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-05-05 18:28:35 -0400
commit86f55d8aa12268fe847eaa344e8efbab5d293f34 (patch)
tree6bbc5c6fb6825ef969ed0342e4851667b81577cc /src/server/authentication/DashUserModel.ts
parent2a9db784a6e3492a8f7d8ce9a745b4f1a0494241 (diff)
parent139600ab7e8a82a31744cd3798247236cd5616fc (diff)
Merge branch 'nathan-starter' of https://github.com/brown-dash/Dash-Web into nathan-starter
Diffstat (limited to 'src/server/authentication/DashUserModel.ts')
-rw-r--r--src/server/authentication/DashUserModel.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/server/authentication/DashUserModel.ts b/src/server/authentication/DashUserModel.ts
index dbb7a79ed..bfa6d7bdb 100644
--- a/src/server/authentication/DashUserModel.ts
+++ b/src/server/authentication/DashUserModel.ts
@@ -1,9 +1,8 @@
-//@ts-ignore
import * as bcrypt from 'bcrypt-nodejs';
-//@ts-ignore
import * as mongoose from 'mongoose';
import { Utils } from '../../Utils';
+type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => void) => void;
export type DashUserModel = mongoose.Document & {
email: String;
password: string;
@@ -26,8 +25,6 @@ export type DashUserModel = mongoose.Document & {
comparePassword: comparePasswordFunction;
};
-type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => void) => void;
-
export type AuthToken = {
accessToken: string;
kind: string;
@@ -64,7 +61,7 @@ const userSchema = new mongoose.Schema(
* Password hash middleware.
*/
userSchema.pre('save', function save(next) {
- const user = this as any as DashUserModel;
+ const user = this;
if (!user.isModified('password')) {
return next();
}
@@ -73,18 +70,21 @@ userSchema.pre('save', function save(next) {
return next(err);
}
bcrypt.hash(
- user.password,
+ user.password ?? '',
salt,
- () => void {},
- (err: mongoose.Error, hash: string) => {
- if (err) {
- return next(err);
+ () => {},
+ (cryptErr: mongoose.Error, hash: string) => {
+ if (cryptErr) {
+ return next(cryptErr);
}
user.password = hash;
next();
+ return undefined;
}
);
+ return undefined;
});
+ return undefined;
});
const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) {
@@ -97,7 +97,7 @@ const comparePassword: comparePasswordFunction = function (this: DashUserModel,
userSchema.methods.comparePassword = comparePassword;
-const User = mongoose.model('User', userSchema);
+const User: any = mongoose.model('User', userSchema);
export function initializeGuest() {
new User({
email: 'guest',