Added the verified & verificationSecret field to the Account model
This commit is contained in:
parent
2777aea903
commit
bc68da563a
@ -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);
|
Loading…
x
Reference in New Issue
Block a user