@flink-app/generic-auth-plugin 0.12.1-alpha.27 → 0.12.1-alpha.29
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.
- package/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.ts +1 -1
- package/.flink/start.ts +1 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/start.js +1 -1
- package/dist/src/coreFunctions.d.ts +3 -3
- package/dist/src/coreFunctions.js +2 -2
- package/dist/src/genericAuthContext.d.ts +3 -3
- package/dist/src/genericAuthPluginOptions.d.ts +2 -1
- package/dist/src/handlers/UserLogin.js +39 -7
- package/package.json +2 -2
- package/src/coreFunctions.ts +5 -4
- package/src/genericAuthContext.ts +4 -3
- package/src/genericAuthPluginOptions.ts +2 -1
- package/src/handlers/UserLogin.ts +56 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
|
|
3
3
|
import * as UserCreate_0 from "../src/handlers/UserCreate";
|
|
4
4
|
import * as UserLogin_0 from "../src/handlers/UserLogin";
|
package/.flink/generatedJobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredJobs } from "@flink-app/flink";
|
|
3
3
|
export const jobs = [];
|
|
4
4
|
autoRegisteredJobs.push(...jobs);
|
package/.flink/generatedRepos.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
export const repos = [];
|
|
4
4
|
autoRegisteredRepos.push(...repos);
|
|
@@ -29,7 +29,7 @@ import { PutManagementUserRolesByUseridRes } from "../../src/schemas/Management/
|
|
|
29
29
|
import { PutManagementUserUsernameByUseridReq } from "../../src/schemas/Management/PutUserUsernameByUseridReq";
|
|
30
30
|
import { PutManagementUserUsernameByUseridRes } from "../../src/schemas/Management/PutUserUsernameByUseridRes";
|
|
31
31
|
|
|
32
|
-
// Generated
|
|
32
|
+
// Generated Mon Sep 22 2025 13:48:38 GMT+0200 (Central European Summer Time)
|
|
33
33
|
export interface UserCreate_7_ReqSchema extends UserCreateReq {}
|
|
34
34
|
|
|
35
35
|
export interface UserCreate_7_ResSchema extends UserCreateRes {}
|
package/.flink/start.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlers = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.handlers = [];
|
|
7
7
|
flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jobs = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.jobs = [];
|
|
7
7
|
flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.repos = void 0;
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.repos = [];
|
|
7
7
|
flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
|
package/dist/.flink/start.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated Mon Sep 22 2025 13:48:37 GMT+0200 (Central European Summer Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
import { User } from "./schemas/User";
|
|
4
4
|
import { UserCreateRes } from "./schemas/UserCreateRes";
|
|
@@ -23,8 +23,8 @@ export declare function loginByToken(repo: FlinkRepo<any, User>, auth: JwtAuthPl
|
|
|
23
23
|
export declare function loginUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string | undefined, validatePasswordMethod?: {
|
|
24
24
|
(password: string, hash: string, salt: string): Promise<boolean>;
|
|
25
25
|
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: {
|
|
26
|
-
(user: User): Promise<void>;
|
|
27
|
-
}): Promise<UserLoginRes>;
|
|
26
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
27
|
+
}, req?: FlinkRequest): Promise<UserLoginRes>;
|
|
28
28
|
export declare function changePassword(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, userId: string, newPassword: string, createPasswordHashAndSaltMethod?: {
|
|
29
29
|
(password: string): Promise<{
|
|
30
30
|
hash: string;
|
|
@@ -190,7 +190,7 @@ function loginByToken(repo, auth, token, code, jwtSecret) {
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
exports.loginByToken = loginByToken;
|
|
193
|
-
function loginUser(repo, auth, username, password, validatePasswordMethod, smsOptions, onSuccessfulLogin) {
|
|
193
|
+
function loginUser(repo, auth, username, password, validatePasswordMethod, smsOptions, onSuccessfulLogin, req) {
|
|
194
194
|
return __awaiter(this, void 0, void 0, function () {
|
|
195
195
|
var user, valid, ex_1, code, payload, secret, options, token, token;
|
|
196
196
|
return __generator(this, function (_a) {
|
|
@@ -262,7 +262,7 @@ function loginUser(repo, auth, username, password, validatePasswordMethod, smsOp
|
|
|
262
262
|
case 10:
|
|
263
263
|
token = _a.sent();
|
|
264
264
|
if (!onSuccessfulLogin) return [3 /*break*/, 12];
|
|
265
|
-
return [4 /*yield*/, onSuccessfulLogin(user)];
|
|
265
|
+
return [4 /*yield*/, onSuccessfulLogin(user, req)];
|
|
266
266
|
case 11:
|
|
267
267
|
_a.sent();
|
|
268
268
|
_a.label = 12;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
import { User } from "./schemas/User";
|
|
4
4
|
import { UserCreateRes } from "./schemas/UserCreateRes";
|
|
@@ -13,7 +13,7 @@ export interface genericAuthContext {
|
|
|
13
13
|
genericAuthPlugin: {
|
|
14
14
|
loginUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password?: string, validatePasswordMethod?: {
|
|
15
15
|
(password: string, hash: string, salt: string): Promise<boolean>;
|
|
16
|
-
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: (user: User) => Promise<void
|
|
16
|
+
}, smsOptions?: GenericAuthsmsOptions, onSuccessfulLogin?: (user: User, req?: FlinkRequest) => Promise<void>, req?: FlinkRequest): Promise<UserLoginRes>;
|
|
17
17
|
loginByToken(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, token: string, code: string, jwtSecret: string): Promise<UserLoginRes>;
|
|
18
18
|
createUser(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, username: string, password: string, authentificationMethod: "password" | "sms" | "bankid", roles: string[], profile: UserProfile, createPasswordHashAndSaltMethod?: {
|
|
19
19
|
(password: string): Promise<{
|
|
@@ -48,7 +48,7 @@ export interface genericAuthContext {
|
|
|
48
48
|
usernameFormat: RegExp;
|
|
49
49
|
smsOptions?: GenericAuthsmsOptions;
|
|
50
50
|
onSuccessfulLogin?: {
|
|
51
|
-
(user: User): Promise<void>;
|
|
51
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
52
52
|
};
|
|
53
53
|
onUserCreated?: {
|
|
54
54
|
(user: User): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlinkRequest } from "@flink-app/flink";
|
|
1
2
|
import { User } from "./schemas/User";
|
|
2
3
|
import { UserPasswordResetSettings } from "./schemas/UserPasswordResetSettings";
|
|
3
4
|
import { client as smsClient } from "@flink-app/sms-plugin";
|
|
@@ -26,7 +27,7 @@ export interface GenericAuthPluginOptions {
|
|
|
26
27
|
usernameFormat?: RegExp;
|
|
27
28
|
sms?: GenericAuthsmsOptions;
|
|
28
29
|
onSuccessfulLogin?: {
|
|
29
|
-
(user: User): Promise<void>;
|
|
30
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
30
31
|
};
|
|
31
32
|
onUserCreated?: {
|
|
32
33
|
(user: User): Promise<void>;
|
|
@@ -39,29 +39,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
41
|
var userLoginHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
42
|
-
var pluginName, repo,
|
|
42
|
+
var pluginName, repo, loginResponse, error_1;
|
|
43
43
|
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
44
44
|
return __generator(this, function (_c) {
|
|
45
45
|
switch (_c.label) {
|
|
46
46
|
case 0:
|
|
47
47
|
pluginName = origin || "genericAuthPlugin";
|
|
48
48
|
repo = ctx.repos[ctx.plugins[pluginName].repoName];
|
|
49
|
-
|
|
49
|
+
loginResponse = undefined;
|
|
50
|
+
_c.label = 1;
|
|
50
51
|
case 1:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
_c.trys.push([1, 3, , 4]);
|
|
53
|
+
return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginUser(repo, ctx.auth, req.body.username, req.body.password, ctx.plugins.genericAuthPlugin.validatePasswordMethod, ctx.plugins[pluginName].smsOptions, ctx.plugins[pluginName].onSuccessfulLogin, req)];
|
|
54
|
+
case 2:
|
|
55
|
+
loginResponse = _c.sent();
|
|
56
|
+
return [3 /*break*/, 4];
|
|
57
|
+
case 3:
|
|
58
|
+
error_1 = _c.sent();
|
|
59
|
+
// Convert any thrown error that conforms to flink error structure to a proper response
|
|
60
|
+
// Note that any auth failures would not have been thrown, but returned as part of loginResponse
|
|
61
|
+
// but with this it is possible to throw errors from callbacks like onSuccessfulLogin
|
|
62
|
+
if (isFlinkError(error_1)) {
|
|
63
|
+
flink_1.log.debug("Caught FlinkError in userLoginHandler:", error_1);
|
|
64
|
+
return [2 /*return*/, {
|
|
65
|
+
status: error_1.status,
|
|
66
|
+
error: {
|
|
67
|
+
id: error_1.id,
|
|
68
|
+
title: error_1.title,
|
|
69
|
+
code: error_1.code,
|
|
70
|
+
detail: error_1.detail,
|
|
71
|
+
},
|
|
72
|
+
}];
|
|
73
|
+
}
|
|
74
|
+
// For other errors, return a generic 500 response
|
|
75
|
+
flink_1.log.error("Error in userLoginHandler:", error_1);
|
|
76
|
+
return [2 /*return*/, (0, flink_1.internalServerError)()];
|
|
77
|
+
case 4:
|
|
78
|
+
if ((loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) != "success") {
|
|
79
|
+
switch (loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) {
|
|
54
80
|
case "failed":
|
|
55
|
-
return [2 /*return*/, (0, flink_1.unauthorized)("Invalid username or password",
|
|
81
|
+
return [2 /*return*/, (0, flink_1.unauthorized)("Invalid username or password", loginResponse.status)];
|
|
56
82
|
}
|
|
57
83
|
}
|
|
58
84
|
return [2 /*return*/, {
|
|
59
|
-
data:
|
|
85
|
+
data: loginResponse,
|
|
60
86
|
status: 200,
|
|
61
87
|
}];
|
|
62
88
|
}
|
|
63
89
|
});
|
|
64
90
|
}); };
|
|
65
91
|
exports.default = userLoginHandler;
|
|
92
|
+
function isFlinkError(res) {
|
|
93
|
+
if (res && res.status && typeof res.status === "number" && res.error && res.error.id) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
66
98
|
exports.__assumedHttpMethod = "", exports.__file = "UserLogin.ts", exports.__query = [], exports.__params = [];
|
|
67
99
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed", "requiresValidation"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" }, "profile": { "type": "object" } }, "required": ["_id", "username", "token", "profile"], "additionalProperties": false }, "validationToken": { "type": "string" } }, "required": ["status"], "definitions": {} } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/generic-auth-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.29",
|
|
4
4
|
"description": "Flink plugin that provides a generic user authentification solution.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-node": "^9.1.1",
|
|
31
31
|
"typescript": "5.4.5"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "40b53cd1ce0d8fc23f942f76b152a754796be01f"
|
|
34
34
|
}
|
package/src/coreFunctions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo, FlinkAuthUser, log } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkAuthUser, log, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin, jwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
|
|
4
4
|
import { User } from "./schemas/User";
|
|
@@ -164,8 +164,9 @@ export async function loginUser(
|
|
|
164
164
|
},
|
|
165
165
|
smsOptions?: GenericAuthsmsOptions,
|
|
166
166
|
onSuccessfulLogin?: {
|
|
167
|
-
(user: User): Promise<void>;
|
|
168
|
-
}
|
|
167
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
168
|
+
},
|
|
169
|
+
req?: FlinkRequest
|
|
169
170
|
): Promise<UserLoginRes> {
|
|
170
171
|
const user = await repo.getOne({ username: username.toLowerCase() });
|
|
171
172
|
if (user == null) {
|
|
@@ -231,7 +232,7 @@ export async function loginUser(
|
|
|
231
232
|
const token = await auth.createToken({ username: username.toLowerCase(), _id: user._id }, user.roles);
|
|
232
233
|
|
|
233
234
|
if (onSuccessfulLogin) {
|
|
234
|
-
await onSuccessfulLogin(user);
|
|
235
|
+
await onSuccessfulLogin(user, req);
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkRepo } from "@flink-app/flink";
|
|
1
|
+
import { FlinkRepo, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
3
3
|
import { User } from "./schemas/User";
|
|
4
4
|
import { UserCreateRes } from "./schemas/UserCreateRes";
|
|
@@ -19,7 +19,8 @@ export interface genericAuthContext {
|
|
|
19
19
|
password?: string,
|
|
20
20
|
validatePasswordMethod?: { (password: string, hash: string, salt: string): Promise<boolean> },
|
|
21
21
|
smsOptions?: GenericAuthsmsOptions,
|
|
22
|
-
onSuccessfulLogin?: (user: User) => Promise<void
|
|
22
|
+
onSuccessfulLogin?: (user: User, req?: FlinkRequest) => Promise<void>,
|
|
23
|
+
req?: FlinkRequest
|
|
23
24
|
): Promise<UserLoginRes>;
|
|
24
25
|
loginByToken(repo: FlinkRepo<any, User>, auth: JwtAuthPlugin, token: string, code: string, jwtSecret: string): Promise<UserLoginRes>;
|
|
25
26
|
createUser(
|
|
@@ -68,7 +69,7 @@ export interface genericAuthContext {
|
|
|
68
69
|
validatePasswordMethod?: { (password: string, hash: string, salt: string): Promise<boolean> };
|
|
69
70
|
usernameFormat: RegExp;
|
|
70
71
|
smsOptions?: GenericAuthsmsOptions;
|
|
71
|
-
onSuccessfulLogin?: { (user: User): Promise<void> };
|
|
72
|
+
onSuccessfulLogin?: { (user: User, req?: FlinkRequest): Promise<void> };
|
|
72
73
|
onUserCreated?: { (user: User): Promise<void> };
|
|
73
74
|
};
|
|
74
75
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlinkRequest } from "@flink-app/flink";
|
|
1
2
|
import { User } from "./schemas/User";
|
|
2
3
|
import { UserPasswordResetSettings } from "./schemas/UserPasswordResetSettings";
|
|
3
4
|
import { client as smsClient } from "@flink-app/sms-plugin";
|
|
@@ -23,7 +24,7 @@ export interface GenericAuthPluginOptions {
|
|
|
23
24
|
usernameFormat?: RegExp;
|
|
24
25
|
sms?: GenericAuthsmsOptions;
|
|
25
26
|
onSuccessfulLogin?: {
|
|
26
|
-
(user: User): Promise<void>;
|
|
27
|
+
(user: User, req?: FlinkRequest): Promise<void>;
|
|
27
28
|
};
|
|
28
29
|
onUserCreated?: {
|
|
29
30
|
(user: User): Promise<void>;
|
|
@@ -1,41 +1,66 @@
|
|
|
1
|
-
import { FlinkContext, Handler, unauthorized } from "@flink-app/flink";
|
|
1
|
+
import { FlinkContext, FlinkResponse, Handler, internalServerError, log, unauthorized } from "@flink-app/flink";
|
|
2
|
+
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
2
3
|
import { genericAuthContext } from "../genericAuthContext";
|
|
3
4
|
import { UserLoginReq } from "../schemas/UserLoginReq";
|
|
4
5
|
import { UserLoginRes } from "../schemas/UserLoginRes";
|
|
5
|
-
import { JwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
|
|
6
6
|
|
|
7
|
-
const userLoginHandler: Handler<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (loginRespons.status != "success") {
|
|
26
|
-
switch (loginRespons.status) {
|
|
27
|
-
case "failed":
|
|
28
|
-
return unauthorized(
|
|
29
|
-
"Invalid username or password",
|
|
30
|
-
loginRespons.status
|
|
7
|
+
const userLoginHandler: Handler<FlinkContext<genericAuthContext>, UserLoginReq, UserLoginRes> = async ({ ctx, req, origin }) => {
|
|
8
|
+
let pluginName = origin || "genericAuthPlugin";
|
|
9
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
10
|
+
|
|
11
|
+
let loginResponse: UserLoginRes | undefined = undefined;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
loginResponse = await ctx.plugins.genericAuthPlugin.loginUser(
|
|
15
|
+
repo,
|
|
16
|
+
<JwtAuthPlugin>ctx.auth,
|
|
17
|
+
req.body.username,
|
|
18
|
+
req.body.password,
|
|
19
|
+
ctx.plugins.genericAuthPlugin.validatePasswordMethod,
|
|
20
|
+
(<any>ctx.plugins)[pluginName].smsOptions,
|
|
21
|
+
(<any>ctx.plugins)[pluginName].onSuccessfulLogin,
|
|
22
|
+
req
|
|
31
23
|
);
|
|
24
|
+
} catch (error: any) {
|
|
25
|
+
// Convert any thrown error that conforms to flink error structure to a proper response
|
|
26
|
+
// Note that any auth failures would not have been thrown, but returned as part of loginResponse
|
|
27
|
+
// but with this it is possible to throw errors from callbacks like onSuccessfulLogin
|
|
28
|
+
if (isFlinkError(error)) {
|
|
29
|
+
log.debug("Caught FlinkError in userLoginHandler:", error);
|
|
30
|
+
return {
|
|
31
|
+
status: error.status,
|
|
32
|
+
error: {
|
|
33
|
+
id: error.id,
|
|
34
|
+
title: error.title,
|
|
35
|
+
code: error.code,
|
|
36
|
+
detail: error.detail,
|
|
37
|
+
},
|
|
38
|
+
} as FlinkResponse;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// For other errors, return a generic 500 response
|
|
42
|
+
log.error("Error in userLoginHandler:", error);
|
|
43
|
+
return internalServerError();
|
|
32
44
|
}
|
|
33
|
-
}
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
if (loginResponse?.status != "success") {
|
|
47
|
+
switch (loginResponse?.status) {
|
|
48
|
+
case "failed":
|
|
49
|
+
return unauthorized("Invalid username or password", loginResponse.status);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
data: loginResponse,
|
|
55
|
+
status: 200,
|
|
56
|
+
};
|
|
39
57
|
};
|
|
40
58
|
|
|
41
59
|
export default userLoginHandler;
|
|
60
|
+
|
|
61
|
+
function isFlinkError(res: any) {
|
|
62
|
+
if (res && res.status && typeof res.status === "number" && res.error && res.error.id) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|