From 04cd867eb13af25d560a19c3b6dd49417f4b337c Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 26 Jun 2022 17:04:24 +0200 Subject: [PATCH] Created the token (session, apikey) model / schema --- models/Token.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 models/Token.js diff --git a/models/Token.js b/models/Token.js new file mode 100644 index 0000000..2fe6437 --- /dev/null +++ b/models/Token.js @@ -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); \ No newline at end of file