From 02bbabd5e11b00b84ce7250273f09be052c2ec1b Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 20 Jul 2024 12:32:51 +0200 Subject: [PATCH] Create Session.ts model --- src/models/Session.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/models/Session.ts 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