Created the Token model

This commit is contained in:
Mathias Wagner 2022-09-08 22:08:06 +02:00
parent 63478822ba
commit 0f623486ce
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

40
models/Token.ts Normal file
View File

@ -0,0 +1,40 @@
import mongoose, {Schema} from 'mongoose';
import * as crypto from "crypto";
export enum TokenType {
API, SESSION
}
export interface IToken {
token: string
clientId: number
type: TokenType
userAgent?: string
created: Date
}
const TokenSchema = new Schema<IToken>({
token: {
type: String,
default: () => crypto.randomBytes(48).toString('hex')
},
clientId: {
type: Number,
required: true
},
type: {
type: Number,
enum: TokenType,
default: TokenType.SESSION
},
userAgent: {
type: String,
required: false
},
created: {
type: Date,
default: Date.now
}
});
export const Token = mongoose.model('tokens', TokenSchema);