Move user token signing to UserManager

Only the controller has access to the secret needed to sign user tokens
so it makes sense for the user signing code to live in the controller.
This saves about 20ms on the time ctl takes to start up due to lib no
longer needing to import jsonwebtoken.
This commit is contained in:
Hornwitser committed 2023-07-28 16:03:29 +02:00
1 parent 6af25e085c
commit a5c7eb3a27
7 files changed
+20 -21

No files matched your search

-12
View File
@@ -7,8 +7,6 @@
* @module lib/users
*/
"use strict";
const jwt = require("jsonwebtoken");
const libErrors = require("./errors");
const PlayerStats = require("./PlayerStats");
@@ -257,16 +255,6 @@ class User {
return serialized;
}
/**
* Generate access token for this user
*
* @param {string} secret - Secret to sign token with.
* @returns {string} JWT access token for the user.
*/
createToken(secret) {
return jwt.sign({ aud: "user", user: this.name }, Buffer.from(secret, "base64"));
}
/**
* Invalidate current tokens for the user
*