diff --git a/models/user.ts b/models/user.ts index 863f081..312b43b 100644 --- a/models/user.ts +++ b/models/user.ts @@ -1,4 +1,4 @@ -import mongoose, { PopulatedDoc, Document, Model } from "mongoose"; +import mongoose, { Document, Model, PopulatedDoc } from "mongoose"; import SequenceFactory from "mongoose-sequence"; import bcrypt from "bcryptjs"; import md5 from "blueimp-md5"; @@ -7,7 +7,7 @@ import { hasMigrated } from "@dbconfig"; import { IBand } from "./band"; import { IStory } from "./stories/index"; import { QuickMenuItem, QuickMenuSchema } from "./quickMenu"; -import { FilterPick, PopulatedDocKeys, PopulatedPick } from "~/utils/filter"; +// import { FilterPick, PopulatedDocKeys, PopulatedPick } from "~/utils/filter"; const AutoIncrement = SequenceFactory(mongoose); interface IIPLogEntry { @@ -70,7 +70,8 @@ export interface IUser extends Document { quickMenuConfig: QuickMenuItem[]; notifyOnReviewReply?: boolean; validPassword(password: string): boolean; - generateJWT(jwtSecret: string): string; + generateRefreshToken(jwtSecret: string): string; + generateAccessToken(jwtSecret: string): string; } // type iut = IUser; interface UModel extends Model { @@ -272,11 +273,16 @@ UserSchema.methods.validPassword = function (password: string): boolean { return md5(password) === this.password || bcrypt.compareSync(password, this.password) || false; }; -UserSchema.methods.generateJWT = function (jwtKey: string): string { - let token = jwt.sign({ id: this._id, isAdmin: this.profile.isAdmin }, jwtKey, { +UserSchema.methods.generateRefreshToken = function (jwtKey: string): string { + return jwt.sign({ id: this._id, isAdmin: this.profile.isAdmin }, jwtKey, { expiresIn: "14 days", }); - return token; +}; + +UserSchema.methods.generateAccessToken = function (jwtKey: string): string { + return jwt.sign({ id: this._id, isAdmin: this.profile.isAdmin }, jwtKey, { + expiresIn: "15m", + }); }; hasMigrated && !mongoose.models.User && UserSchema.plugin(AutoIncrement, { id: "userid", inc_field: "_id" });