User.js 591 B

123456789101112131415161718192021222324252627
  1. import mongoose from "mongoose";
  2. const ROLES = ["user", "admin"];
  3. const UserSchema = new mongoose.Schema(
  4. {
  5. username: {
  6. type: String,
  7. required: true,
  8. unique: true,
  9. },
  10. password: {
  11. type: String,
  12. required: true,
  13. },
  14. points: { type: Number, default: 0 },
  15. role: { type: String, enum: ROLES, default: "user" },
  16. securityQuestion: {
  17. type: String,
  18. },
  19. securityAnswer: { type: String },
  20. lastLoginAt: { type: Date },
  21. },
  22. { timestamps: true }
  23. );
  24. export default mongoose.models.User || mongoose.model("User", UserSchema);