aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/DashUserModel.ts
diff options
context:
space:
mode:
authorsharkiecodes <lanyi_stroud@brown.edu>2025-07-22 12:35:43 -0400
committersharkiecodes <lanyi_stroud@brown.edu>2025-07-22 12:35:43 -0400
commitd31a740378e8d4fd58ec329ba83dd20d28bfe5b4 (patch)
treeb46103d4f9fd2b04ccfc25023e1cb0156168f412 /src/server/authentication/DashUserModel.ts
parent62f9b89dad334d3d6405f5286e66b253090a82c7 (diff)
parent3f489c64d9e55d452c255f8e2c10b0d754883dbb (diff)
Merge branch 'master' into lanyi-expanded-agent-paper-main
Diffstat (limited to 'src/server/authentication/DashUserModel.ts')
-rw-r--r--src/server/authentication/DashUserModel.ts87
1 files changed, 45 insertions, 42 deletions
diff --git a/src/server/authentication/DashUserModel.ts b/src/server/authentication/DashUserModel.ts
index 6fd8dd593..7aa7f2598 100644
--- a/src/server/authentication/DashUserModel.ts
+++ b/src/server/authentication/DashUserModel.ts
@@ -3,30 +3,31 @@ import * as mongoose from 'mongoose';
import { Utils } from '../../Utils';
type comparePasswordFunction = (candidatePassword: string, cb: (err: Error, isMatch: boolean) => void) => void;
-type mongooseDocument = { id: string }; // & mongoose.Document;
-export type DashUserModel = mongooseDocument & {
- email: string;
- password: string;
- passwordResetToken?: string;
- passwordResetExpires?: Date;
+export type DashUserModel = mongoose.Document & {
+ email?: string | null | undefined;
+ password?: string | null | undefined;
+ passwordResetToken?: string | null | undefined;
+ passwordResetExpires?: Date | null | undefined;
- dropboxRefresh?: string;
- dropboxToken?: string;
+ dropboxRefresh?: string | null | undefined;
+ dropboxToken?: string | null | undefined;
- userDocumentId: string;
- sharingDocumentId: string;
- linkDatabaseId: string;
- cacheDocumentIds: string;
+ userDocumentId?: string | null | undefined;
+ sharingDocumentId?: string | null | undefined;
+ linkDatabaseId?: string | null | undefined;
+ cacheDocumentIds?: string | null | undefined;
+ profile?:
+ | {
+ name?: string | null | undefined;
+ gender?: string | null | undefined;
+ location?: string | null | undefined;
+ website?: string | null | undefined;
+ picture?: string | null | undefined;
+ }
+ | null
+ | undefined;
- profile: {
- name: string;
- gender: string;
- location: string;
- website: string;
- picture: string;
- };
-
- comparePassword: comparePasswordFunction;
+ comparePassword?: comparePasswordFunction | null | undefined;
};
export type AuthToken = {
@@ -68,36 +69,38 @@ const userSchema = new mongoose.Schema(
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
userSchema.pre('save', function save(next: any) {
- const user = this;
- if (!user.isModified('password')) {
+ if (!this.isModified('password')) {
return next();
}
- bcrypt.genSalt(10, (err: Error, salt: string) => {
- if (err) {
- return next(err);
- }
- bcrypt.hash(
- user.password ?? '',
- salt,
- () => {},
- (cryptErr: mongoose.Error, hash: string) => {
- if (cryptErr) {
- return next(cryptErr);
- }
- user.password = hash;
- next();
- return undefined;
+ bcrypt.genSalt(
+ 10,
+ ((err: Error, salt: string) => {
+ if (err) {
+ return next(err);
}
- );
- return undefined;
- });
+ bcrypt.hash(
+ this.password ?? '',
+ salt,
+ () => {},
+ (cryptErr: mongoose.Error, hash: string) => {
+ if (cryptErr) {
+ return next(cryptErr);
+ }
+ this.password = hash;
+ next();
+ return undefined;
+ }
+ );
+ return undefined;
+ }).bind(this)
+ );
return undefined;
});
const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) {
// Choose one of the following bodies for authentication logic.
// secure (expected, default)
- bcrypt.compare(candidatePassword, this.password, cb);
+ this.password && bcrypt.compare(candidatePassword, this.password, cb);
// bypass password (debugging)
// cb(undefined, true);
};