Created the token (session, apikey) model / schema
This commit is contained in:
parent
5f5247c88c
commit
04cd867eb1
28
models/Token.js
Normal file
28
models/Token.js
Normal file
@ -0,0 +1,28 @@
|
||||
const mongoose = require('mongoose');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TokenSchema = new mongoose.Schema({
|
||||
token: { // The token used to log in to the user account
|
||||
type: String,
|
||||
default: () => crypto.randomBytes(48).toString('hex')
|
||||
},
|
||||
user_id: { // The user id to which the token logs in
|
||||
type: mongoose.Schema.ObjectId,
|
||||
required: true
|
||||
},
|
||||
type: { // The type of the token
|
||||
type: String,
|
||||
enum: ["api", "session"],
|
||||
default: "session"
|
||||
},
|
||||
user_agent: { // The user agent of the browser
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
created: { // The date when the session has been created
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('tokens', TokenSchema);
|
Loading…
x
Reference in New Issue
Block a user