mirror of
https://github.com/gnmyt/LicenseAPI.git
synced 2026-01-11 02:31:46 +00:00
Create Session.ts model
This commit is contained in:
30
src/models/Session.ts
Normal file
30
src/models/Session.ts
Normal 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);
|
||||
Reference in New Issue
Block a user