Agromind-backend / backend /models /userModel.js
gh-action-hf-auto
auto: sync backend from github@32fb9685
8a6248c
import mongoose from 'mongoose';
const deviceSchema = new mongoose.Schema(
{
deviceId: { type: String, required: true },
label: { type: String, default: 'Unknown Device' },
lastSeen: { type: Date, default: Date.now },
},
{ _id: false },
);
const UserSchema = new mongoose.Schema(
{
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String }, // optional: Google/OAuth users have no password
role: { type: String, enum: ['farmer', 'expert', 'admin'], default: 'farmer' },
img: { type: String },
country: { type: String },
phone: { type: String },
desc: { type: String },
isSeller: { type: Boolean, default: false },
// ── Firebase / Google OAuth link ─────────────────────────────────────
// Stored so that register-device and other routes can look up the user
// by Firebase UID instead of MongoDB _id when using Google sign-in.
firebaseUid: { type: String, sparse: true, index: true },
language: { type: String, default: 'en' },
// ── Cross-device login tracking ──────────────────────────────────────
devices: { type: [deviceSchema], default: [] },
},
{ timestamps: true },
);
export default mongoose.models.User || mongoose.model('User', UserSchema);