pangea-server 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import { AccessToken } from './access-token.class';
|
|
|
2
2
|
import { User } from '../database';
|
|
3
3
|
import type { UserCtor, AuthMap } from './authentication.types';
|
|
4
4
|
type AuthHeader = string | undefined;
|
|
5
|
-
export declare function login(authHeader: AuthHeader, tx: Tx, accessToken: AccessToken, userCtor:
|
|
5
|
+
export declare function login<U extends User>(authHeader: AuthHeader, tx: Tx, accessToken: AccessToken, userCtor: BaseModelCtor<U>, extraWhere?: Where<U>): Promise<{
|
|
6
6
|
accessToken: string;
|
|
7
7
|
user: User;
|
|
8
8
|
}>;
|
|
@@ -5,7 +5,7 @@ exports.getUsersFromToken = exports.getUserFromToken = exports.validateAccessTok
|
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
// database
|
|
7
7
|
const database_1 = require("../database");
|
|
8
|
-
async function login(authHeader, tx, accessToken, userCtor) {
|
|
8
|
+
async function login(authHeader, tx, accessToken, userCtor, extraWhere = {}) {
|
|
9
9
|
if (!authHeader?.startsWith('Basic '))
|
|
10
10
|
helpers_1.AppError.ThrowInvalidCredentials();
|
|
11
11
|
const base64 = authHeader.slice(6);
|
|
@@ -14,7 +14,8 @@ async function login(authHeader, tx, accessToken, userCtor) {
|
|
|
14
14
|
if (!username || !password)
|
|
15
15
|
helpers_1.AppError.ThrowInvalidCredentials();
|
|
16
16
|
const db = new database_1.Db(tx);
|
|
17
|
-
const
|
|
17
|
+
const where = { ...extraWhere, username };
|
|
18
|
+
const user = await db.findOneOrNull(userCtor, where, { scopes: ['withExcludedAttributes'] });
|
|
18
19
|
if (!user)
|
|
19
20
|
helpers_1.AppError.ThrowInvalidCredentials();
|
|
20
21
|
const isPasswordValid = await (0, helpers_1.comparePasswords)(password, user.password);
|
|
@@ -5,6 +5,6 @@ export declare abstract class BaseAuth<AM extends AuthMap> {
|
|
|
5
5
|
free(): void;
|
|
6
6
|
notSetYet(): void;
|
|
7
7
|
notAllowed(): void;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
getUserAuth<T extends UserType<AM>>(type: T): NonNullable<AuthUsers<AM>[T]>;
|
|
9
|
+
getUsersAuth<const T extends readonly UserType<AM>[]>(types: T): { [I in keyof T]: InstanceType<AM[T[I]]> | null; };
|
|
10
10
|
}
|
|
@@ -16,13 +16,13 @@ class BaseAuth {
|
|
|
16
16
|
notAllowed() {
|
|
17
17
|
helpers_1.AppError.ThrowUnauthorized();
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
getUserAuth(type) {
|
|
20
20
|
const user = this.__authUsers[type];
|
|
21
21
|
if (!user)
|
|
22
22
|
helpers_1.AppError.ThrowUnauthorized();
|
|
23
23
|
return user;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
getUsersAuth(types) {
|
|
26
26
|
const users = types.map((type) => this.__authUsers[type]);
|
|
27
27
|
if (users.every((user) => !user))
|
|
28
28
|
helpers_1.AppError.ThrowUnauthorized();
|