Migrated auth to Nitro
This commit is contained in:
1 parent
27feb1ce95
commit
eb4e9f0700
16 files changed
+517
-129
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { randomUUID } from "node:crypto"
|
||||
import mongoose, { Schema, type Model } from "mongoose"
|
||||
|
||||
export function getSessionModel(sessionTtlMs: number) {
|
||||
if (mongoose.models.Session) return mongoose.models.Session as Model<any>
|
||||
|
||||
const sessionSchema = new Schema({
|
||||
token: { type: String, default: () => randomUUID(), required: true },
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
index: { expires: Math.floor(sessionTtlMs / 1000) },
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: "User", required: true },
|
||||
})
|
||||
|
||||
return mongoose.model<any>("Session", sessionSchema)
|
||||
}
|
||||
Reference in new issue
Block a user