Created the Token model
This commit is contained in:
parent
63478822ba
commit
0f623486ce
40
models/Token.ts
Normal file
40
models/Token.ts
Normal 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);
|
Loading…
x
Reference in New Issue
Block a user