1export default app => {
2 const mongoose = app.mongoose;
3 const Schema = mongoose.Schema;
4
5 const VerifyCodeSchema = new Schema(
6 {
7 value: { type: String, unique: true }, // code value
8 type: { type: String, enum: ['email'] }, // verification code type
9 operation: { type: String, enum: ['login'] }, // type of operation
10 account: { type: String },
11 createdAt: { type: Date, default: Date.now, index: { expires: 300 } }, // set ttl, failure is automatically deleted after 5m
12 },
13 {
14 usePushEach: true,
15 },
16 );
17
18 return mongoose.model('verifyCode', VerifyCodeSchema);
19};