Created the token (session, apikey) model / schema

This commit is contained in:
Mathias Wagner 2022-06-26 17:04:24 +02:00
parent 5f5247c88c
commit 04cd867eb1
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

28
models/Token.js Normal file
View 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);