diff --git a/src/models/Account.ts b/src/models/Account.ts index 749a620..521897f 100644 --- a/src/models/Account.ts +++ b/src/models/Account.ts @@ -1,11 +1,14 @@ import {Schema, ObjectId, model} from "mongoose"; -import encrypt from "mongoose-encryption"; +import { fieldEncryption } from "mongoose-field-encryption"; +import * as process from "process"; export interface IAccount { id: ObjectId, username: string, email: string, password: string, + verified: boolean, + verificationSecret: number | undefined, totpSecret?: string } @@ -22,12 +25,21 @@ const AccountSchema = new Schema({ type: String, required: true }, + verificationSecret: { + type: Number, + default: () => Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000 + }, + verified: { + type: Boolean, + default: false + }, totpSecret: String }); -AccountSchema.plugin(encrypt, { - encryptionKey: process.env.ENC_KEY, - signingKey: process.env.SIG_KEY +AccountSchema.plugin(fieldEncryption, { + fields: ["username", "email", "password", "totpSecret"], + secret: process.env.ENC_KEY, + saltGenerator: () => process.env.SIG_KEY }); export const Account = model("accounts", AccountSchema); \ No newline at end of file