UNPKG

myex-cli

Version:

Opinionated Express.js framework with CLI tools

38 lines (35 loc) 770 B
import mongoose from 'mongoose'; const tokenSchema = new mongoose.Schema( { userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true, }, token: { type: String, required: true, }, type: { type: String, enum: ['refresh', 'reset', 'verification'], required: true, }, expiresAt: { type: Date, required: true, }, isUsed: { type: Boolean, default: false, }, }, { timestamps: true, } ); // Indexes tokenSchema.index({ token: 1 }); tokenSchema.index({ userId: 1, type: 1 }); tokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 }); // TTL index for automatic removal export const Token = mongoose.model('Token', tokenSchema);