Create Session.ts model

This commit is contained in:
Mathias Wagner
2024-07-20 12:32:51 +02:00
parent 4f3b5a83c5
commit 02bbabd5e1

30
src/models/Session.ts Normal file
View File

@ -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<ISession>({
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<ISession>("sessions", SessionSchema);