UNPKG

1.01 kBJavaScriptView Raw
1"use strict";
2/**
3 * This module contains a set of standard verifiers to ensure user authentication
4 * and authorization.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.isStaffOrGreater = exports.notAuthUser = exports.authUser = void 0;
8var role_entity_1 = require("./entities/role.entity");
9/**
10 * Verify that the user is authenticated.
11 */
12function authUser(req, _) {
13 if (!req.user || req.user === undefined) {
14 return false;
15 }
16 return true;
17}
18exports.authUser = authUser;
19/**
20 * Verify that the user is NOT authenticated.
21 */
22function notAuthUser(req, res) {
23 return !authUser(req, res);
24}
25exports.notAuthUser = notAuthUser;
26/**
27 * Verify that the user is logged and that is at least a Staff member.
28 */
29function isStaffOrGreater(req, res) {
30 if (!authUser(req, res)) {
31 return false;
32 }
33 if (req.user.level >= role_entity_1.default.STAFF_LEVEL) {
34 return true;
35 }
36 return false;
37}
38exports.isStaffOrGreater = isStaffOrGreater;