forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.js
More file actions
50 lines (47 loc) · 993 Bytes
/
Copy pathSession.js
File metadata and controls
50 lines (47 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// models/Session.js
import mongoose from "mongoose";
const sessionSchema = new mongoose.Schema(
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
refreshTokenHash: {
type: String,
required: true,
unique: true,
},
family: {
type: String, // UUID
required: true,
index: true,
},
device: {
userAgent: String,
ip: String,
label: String,
},
expiresAt: {
type: Date,
required: true,
},
revokedAt: {
type: Date,
default: null,
},
replacedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: "Session",
default: null,
},
lastUsedAt: {
type: Date,
default: Date.now,
},
},
{ timestamps: true }
);
// TTL index on expiresAt. Mongo cleans this up lazily.
sessionSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
export default mongoose.model("Session", sessionSchema);