authenticator logic
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Erik 2023-03-22 19:25:23 +02:00
parent bf4663d307
commit 636f39db5f
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
2 changed files with 7 additions and 8 deletions

View File

@ -145,16 +145,14 @@ class UserDatabase extends UserDatabaseInterface {
if (app)
return Promise.resolve(app);
const data = await this.db.findOne(this._appCollection, { 'token.encrypted': token });
const data = await this.db.findOne(this._appCollection, { token });
if (!data)
return null;
const user = await this.fetchUser(data.user);
app = this._createApp(user, data);
app = this._createApp(data);
if (!this.disableCache)
this.cache.set(app.id, app);
user.attachApplication(app);
return app;

View File

@ -155,9 +155,9 @@ class Authenticator {
const key = segments[segments.length - 1];
const application = await this.userdb.matchToken(key);
if (application)
req.user = application;
else {
if (application) {
req.user = application;
} else {
res.status(401).send('Unknown identity');
return false;
}
@ -179,10 +179,11 @@ class Authenticator {
PermissionManager.ensurePermission(permission);
const func = async (req, res, next) => {
const { user } = req;
// Request does not have a user bound to it, response already sent from #_authenticate
if (!await this.#_authenticate(req, res))
return;
// If the authentication is done through a token, the user will be attached in the authentication step
const { user } = req;
// Has permission
if (user.hasPermission(permission, level))
return next();