ai-adventure-labs/server/api/utils/gen-token.js
2025-08-17 17:55:23 +03:00

20 lines
489 B
JavaScript

function randint(min, max) {
return Math.ceil(Math.random() * (max - min) + min);
}
module.exports = function () {
return Buffer.from([...new Array(128)].map(() => randint(0, 255))).toString(
"base64",
);
};
module.exports.registerToken = function (user) {
let token;
do {
token = module.exports();
} while (global.authed.tokens[token] !== undefined);
global.authed.tokens[token] = user;
// TODO: Потом добавить регистрацию в БД!
return token;
};