From f07187691d99d6dea2f41da48a71e65071857c7d Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 15 Jan 2023 18:43:47 +0100 Subject: [PATCH] Migrated the Session.ts model -> mongoose-field-encryption --- src/models/Session.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/models/Session.ts b/src/models/Session.ts index e88b030..2607138 100644 --- a/src/models/Session.ts +++ b/src/models/Session.ts @@ -1,10 +1,12 @@ import {model, ObjectId, Schema, Types} from "mongoose"; -import encrypt from "mongoose-encryption"; +import { fieldEncryption } from "mongoose-field-encryption"; +import process from "process"; interface ISession { id: ObjectId, userId: ObjectId, token: string, + ip: string, userAgent: string, verified: boolean } @@ -18,6 +20,7 @@ const SessionSchema = new Schema({ type: String, required: true }, + ip: String, userAgent: String, verified: { type: Boolean, @@ -25,9 +28,10 @@ const SessionSchema = new Schema({ } }); -SessionSchema.plugin(encrypt, { - encryptionKey: process.env.ENC_KEY, - signingKey: process.env.SIG_KEY +SessionSchema.plugin(fieldEncryption, { + fields: ["userId", "token", "ip", "userAgent"], + secret: process.env.ENC_KEY, + saltGenerator: () => process.env.SIG_KEY }); export const Session = model("sessions", SessionSchema); \ No newline at end of file