diff --git a/src/models/Session.ts b/src/models/Session.ts new file mode 100644 index 0000000..01b02e5 --- /dev/null +++ b/src/models/Session.ts @@ -0,0 +1,30 @@ +import {model, ObjectId, Schema, Types} from "mongoose"; +import crypto from "crypto"; + +export interface ISession { + _id: ObjectId, + userId: ObjectId, + token: string, + ip: string, + userAgent: string, + verified: boolean +} + +const SessionSchema = new Schema({ + userId: { + type: Types.ObjectId, + required: true + }, + token: { + type: String, + default: () => crypto.randomBytes(48).toString("hex") + }, + ip: String, + userAgent: String, + verified: { + type: Boolean, + required: true + } +}); + +export const Session = model("sessions", SessionSchema); \ No newline at end of file