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 {Schema, ObjectId, model} from "mongoose";
|
||||||
import encrypt from "mongoose-encryption";
|
import { fieldEncryption } from "mongoose-field-encryption";
|
||||||
|
import * as process from "process";
|
||||||
|
|
||||||
export interface IAccount {
|
export interface IAccount {
|
||||||
id: ObjectId,
|
id: ObjectId,
|
||||||
username: string,
|
username: string,
|
||||||
email: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
|
verified: boolean,
|
||||||
|
verificationSecret: number | undefined,
|
||||||
totpSecret?: string
|
totpSecret?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +25,21 @@ const AccountSchema = new Schema<IAccount>({
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
verificationSecret: {
|
||||||
|
type: Number,
|
||||||
|
default: () => Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000
|
||||||
|
},
|
||||||
|
verified: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
totpSecret: String
|
totpSecret: String
|
||||||
});
|
});
|
||||||
|
|
||||||
AccountSchema.plugin(encrypt, {
|
AccountSchema.plugin(fieldEncryption, {
|
||||||
encryptionKey: process.env.ENC_KEY,
|
fields: ["username", "email", "password", "totpSecret"],
|
||||||
signingKey: process.env.SIG_KEY
|
secret: process.env.ENC_KEY,
|
||||||
|
saltGenerator: () => process.env.SIG_KEY
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Account = model<IAccount>("accounts", AccountSchema);
|
export const Account = model<IAccount>("accounts", AccountSchema);
|
Loading…
x
Reference in New Issue
Block a user