Added the verified & verificationSecret field to the Account model

This commit is contained in:
Mathias Wagner 2023-01-15 18:38:10 +01:00
parent 2777aea903
commit bc68da563a
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -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<IAccount>({
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<IAccount>("accounts", AccountSchema);