acebase-server 1.16.2 → 1.18.0
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/README.md +180 -10
- package/bin/acebase-server.js +8 -0
- package/build-vars.js +2 -1
- package/dist/cjs/auth.js +88 -88
- package/dist/cjs/cluster.js +6 -56
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +24 -24
- package/dist/cjs/logger.js +73 -73
- package/dist/cjs/middleware/404.js +14 -14
- package/dist/cjs/middleware/admin-only.js +28 -28
- package/dist/cjs/middleware/cache.js +14 -14
- package/dist/cjs/middleware/connection.js +49 -49
- package/dist/cjs/middleware/context.js +20 -20
- package/dist/cjs/middleware/cors.js +50 -50
- package/dist/cjs/middleware/swagger.js +17 -17
- package/dist/cjs/middleware/user.js +57 -57
- package/dist/cjs/oauth-providers/dropbox.js +109 -109
- package/dist/cjs/oauth-providers/facebook.js +85 -85
- package/dist/cjs/oauth-providers/google.js +119 -119
- package/dist/cjs/oauth-providers/index.js +26 -26
- package/dist/cjs/oauth-providers/instagram.js +80 -80
- package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
- package/dist/cjs/oauth-providers/spotify.js +113 -113
- package/dist/cjs/routes/auth-change-password.js +87 -87
- package/dist/cjs/routes/auth-delete.js +52 -52
- package/dist/cjs/routes/auth-forgot-password.js +77 -77
- package/dist/cjs/routes/auth-reset-password.js +97 -97
- package/dist/cjs/routes/auth-signin.js +46 -46
- package/dist/cjs/routes/auth-signout.js +61 -61
- package/dist/cjs/routes/auth-signup.js +142 -142
- package/dist/cjs/routes/auth-state.js +25 -25
- package/dist/cjs/routes/auth-update.js +131 -131
- package/dist/cjs/routes/auth-verify-email.js +71 -71
- package/dist/cjs/routes/auth.js +57 -54
- package/dist/cjs/routes/data-exists.js +33 -33
- package/dist/cjs/routes/data-export.js +48 -48
- package/dist/cjs/routes/data-get.js +70 -66
- package/dist/cjs/routes/data-import.js +54 -54
- package/dist/cjs/routes/data-index-create.js +42 -42
- package/dist/cjs/routes/data-index-delete.js +33 -33
- package/dist/cjs/routes/data-index-list.js +31 -31
- package/dist/cjs/routes/data-query.js +80 -70
- package/dist/cjs/routes/data-reflect.js +97 -86
- package/dist/cjs/routes/data-schema-get.js +36 -36
- package/dist/cjs/routes/data-schema-set.js +30 -30
- package/dist/cjs/routes/data-schema-test.js +43 -43
- package/dist/cjs/routes/data-schemas-list.js +32 -32
- package/dist/cjs/routes/data-set.js +85 -75
- package/dist/cjs/routes/data-sync-changes.js +81 -67
- package/dist/cjs/routes/data-sync-mutations.js +81 -67
- package/dist/cjs/routes/data-transaction.js +159 -139
- package/dist/cjs/routes/data-update.js +86 -75
- package/dist/cjs/routes/data.js +62 -62
- package/dist/cjs/routes/docs.js +258 -251
- package/dist/cjs/routes/meta-info.js +63 -63
- package/dist/cjs/routes/meta-logs.js +49 -49
- package/dist/cjs/routes/meta-ping.js +11 -11
- package/dist/cjs/routes/meta-stats.js +27 -27
- package/dist/cjs/routes/meta.js +19 -19
- package/dist/cjs/routes/oauth2-init.js +54 -54
- package/dist/cjs/routes/oauth2-refresh.js +42 -42
- package/dist/cjs/routes/oauth2-signin.js +265 -265
- package/dist/cjs/routes/webmanager.js +26 -26
- package/dist/cjs/rules.js +380 -167
- package/dist/cjs/sandbox.js +28 -0
- package/dist/cjs/schema/user.js +24 -24
- package/dist/cjs/server.js +410 -407
- package/dist/cjs/settings/email.js +2 -2
- package/dist/cjs/settings/index.js +175 -172
- package/dist/cjs/shared/clients.js +26 -26
- package/dist/cjs/shared/email.js +2 -2
- package/dist/cjs/shared/env.js +2 -2
- package/dist/cjs/shared/error.js +33 -33
- package/dist/cjs/shared/http.js +28 -28
- package/dist/cjs/shared/password.js +45 -45
- package/dist/cjs/shared/rootpath.js +16 -16
- package/dist/cjs/shared/signin.js +143 -143
- package/dist/cjs/shared/simple-fetch.js +76 -76
- package/dist/cjs/shared/tokens.js +79 -79
- package/dist/cjs/shared/validate.js +61 -61
- package/dist/cjs/start.js +119 -53
- package/dist/cjs/test.js +10 -10
- package/dist/cjs/websocket/index.js +331 -319
- package/dist/cjs/websocket/manager.js +15 -15
- package/dist/cjs/websocket/socket.io.js +76 -76
- package/dist/esm/auth.js +75 -75
- package/dist/esm/cluster.js +6 -54
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/logger.js +51 -51
- package/dist/esm/middleware/404.js +10 -10
- package/dist/esm/middleware/admin-only.js +24 -24
- package/dist/esm/middleware/cache.js +10 -10
- package/dist/esm/middleware/connection.js +45 -45
- package/dist/esm/middleware/context.js +16 -16
- package/dist/esm/middleware/cors.js +44 -44
- package/dist/esm/middleware/swagger.js +13 -13
- package/dist/esm/middleware/user.js +44 -44
- package/dist/esm/oauth-providers/dropbox.js +90 -90
- package/dist/esm/oauth-providers/facebook.js +66 -66
- package/dist/esm/oauth-providers/google.js +96 -96
- package/dist/esm/oauth-providers/index.js +18 -18
- package/dist/esm/oauth-providers/instagram.js +61 -61
- package/dist/esm/oauth-providers/oauth-provider.js +16 -16
- package/dist/esm/oauth-providers/spotify.js +92 -92
- package/dist/esm/routes/auth-change-password.js +72 -72
- package/dist/esm/routes/auth-delete.js +37 -37
- package/dist/esm/routes/auth-forgot-password.js +62 -62
- package/dist/esm/routes/auth-reset-password.js +81 -81
- package/dist/esm/routes/auth-signin.js +33 -33
- package/dist/esm/routes/auth-signout.js +47 -47
- package/dist/esm/routes/auth-signup.js +127 -127
- package/dist/esm/routes/auth-state.js +12 -12
- package/dist/esm/routes/auth-update.js +116 -116
- package/dist/esm/routes/auth-verify-email.js +57 -57
- package/dist/esm/routes/auth.js +53 -50
- package/dist/esm/routes/data-exists.js +20 -20
- package/dist/esm/routes/data-export.js +35 -35
- package/dist/esm/routes/data-get.js +56 -52
- package/dist/esm/routes/data-import.js +41 -41
- package/dist/esm/routes/data-index-create.js +28 -28
- package/dist/esm/routes/data-index-delete.js +20 -20
- package/dist/esm/routes/data-index-list.js +18 -18
- package/dist/esm/routes/data-query.js +66 -56
- package/dist/esm/routes/data-reflect.js +83 -72
- package/dist/esm/routes/data-schema-get.js +23 -23
- package/dist/esm/routes/data-schema-set.js +17 -17
- package/dist/esm/routes/data-schema-test.js +29 -29
- package/dist/esm/routes/data-schemas-list.js +19 -19
- package/dist/esm/routes/data-set.js +70 -60
- package/dist/esm/routes/data-sync-changes.js +67 -53
- package/dist/esm/routes/data-sync-mutations.js +67 -53
- package/dist/esm/routes/data-transaction.js +142 -123
- package/dist/esm/routes/data-update.js +71 -60
- package/dist/esm/routes/data.js +58 -58
- package/dist/esm/routes/docs.js +252 -245
- package/dist/esm/routes/meta-info.js +59 -59
- package/dist/esm/routes/meta-logs.js +35 -35
- package/dist/esm/routes/meta-ping.js +7 -7
- package/dist/esm/routes/meta-stats.js +14 -14
- package/dist/esm/routes/meta.js +15 -15
- package/dist/esm/routes/oauth2-init.js +41 -41
- package/dist/esm/routes/oauth2-refresh.js +29 -29
- package/dist/esm/routes/oauth2-signin.js +251 -251
- package/dist/esm/routes/webmanager.js +22 -22
- package/dist/esm/rules.js +374 -163
- package/dist/esm/sandbox.js +12 -0
- package/dist/esm/schema/user.js +19 -19
- package/dist/esm/server.js +395 -387
- package/dist/esm/settings/email.js +1 -1
- package/dist/esm/settings/index.js +168 -165
- package/dist/esm/shared/clients.js +22 -22
- package/dist/esm/shared/email.js +1 -1
- package/dist/esm/shared/env.js +1 -1
- package/dist/esm/shared/error.js +25 -25
- package/dist/esm/shared/http.js +22 -22
- package/dist/esm/shared/password.js +38 -38
- package/dist/esm/shared/rootpath.js +13 -13
- package/dist/esm/shared/signin.js +128 -128
- package/dist/esm/shared/simple-fetch.js +59 -59
- package/dist/esm/shared/tokens.js +72 -72
- package/dist/esm/shared/validate.js +41 -41
- package/dist/esm/start.js +116 -50
- package/dist/esm/test.js +8 -8
- package/dist/esm/websocket/index.js +313 -302
- package/dist/esm/websocket/manager.js +11 -11
- package/dist/esm/websocket/socket.io.js +71 -71
- package/dist/types/auth.d.ts +3 -3
- package/dist/types/cluster.d.ts +6 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger.d.ts +35 -35
- package/dist/types/middleware/404.d.ts +7 -7
- package/dist/types/middleware/admin-only.d.ts +19 -19
- package/dist/types/middleware/cache.d.ts +3 -3
- package/dist/types/middleware/connection.d.ts +7 -7
- package/dist/types/middleware/context.d.ts +3 -3
- package/dist/types/middleware/cors.d.ts +25 -25
- package/dist/types/middleware/swagger.d.ts +3 -3
- package/dist/types/middleware/user.d.ts +2 -2
- package/dist/types/oauth-providers/dropbox.d.ts +52 -52
- package/dist/types/oauth-providers/facebook.d.ts +41 -41
- package/dist/types/oauth-providers/google.d.ts +43 -43
- package/dist/types/oauth-providers/index.d.ts +10 -10
- package/dist/types/oauth-providers/instagram.d.ts +50 -50
- package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
- package/dist/types/oauth-providers/spotify.d.ts +53 -53
- package/dist/types/routes/auth-change-password.d.ts +20 -20
- package/dist/types/routes/auth-delete.d.ts +16 -16
- package/dist/types/routes/auth-forgot-password.d.ts +16 -16
- package/dist/types/routes/auth-reset-password.d.ts +23 -23
- package/dist/types/routes/auth-signin.d.ts +24 -24
- package/dist/types/routes/auth-signout.d.ts +14 -14
- package/dist/types/routes/auth-signup.d.ts +32 -32
- package/dist/types/routes/auth-state.d.ts +13 -13
- package/dist/types/routes/auth-update.d.ts +33 -33
- package/dist/types/routes/auth-verify-email.d.ts +21 -21
- package/dist/types/routes/auth.d.ts +6 -6
- package/dist/types/routes/data-exists.d.ts +9 -9
- package/dist/types/routes/data-export.d.ts +10 -10
- package/dist/types/routes/data-get.d.ts +14 -14
- package/dist/types/routes/data-import.d.ts +13 -13
- package/dist/types/routes/data-index-create.d.ts +51 -51
- package/dist/types/routes/data-index-delete.d.ts +17 -17
- package/dist/types/routes/data-index-list.d.ts +21 -21
- package/dist/types/routes/data-query.d.ts +49 -49
- package/dist/types/routes/data-reflect.d.ts +29 -29
- package/dist/types/routes/data-schema-get.d.ts +11 -11
- package/dist/types/routes/data-schema-set.d.ts +20 -19
- package/dist/types/routes/data-schema-test.d.ts +19 -19
- package/dist/types/routes/data-schemas-list.d.ts +11 -11
- package/dist/types/routes/data-set.d.ts +27 -27
- package/dist/types/routes/data-sync-changes.d.ts +25 -28
- package/dist/types/routes/data-sync-mutations.d.ts +25 -28
- package/dist/types/routes/data-transaction.d.ts +34 -34
- package/dist/types/routes/data-update.d.ts +27 -27
- package/dist/types/routes/data.d.ts +3 -3
- package/dist/types/routes/docs.d.ts +3 -3
- package/dist/types/routes/meta-info.d.ts +11 -11
- package/dist/types/routes/meta-logs.d.ts +20 -20
- package/dist/types/routes/meta-ping.d.ts +7 -7
- package/dist/types/routes/meta-stats.d.ts +13 -13
- package/dist/types/routes/meta.d.ts +3 -3
- package/dist/types/routes/oauth2-init.d.ts +13 -13
- package/dist/types/routes/oauth2-refresh.d.ts +17 -17
- package/dist/types/routes/oauth2-signin.d.ts +15 -15
- package/dist/types/routes/webmanager.d.ts +3 -3
- package/dist/types/rules.d.ts +73 -34
- package/dist/types/sandbox.d.ts +3 -0
- package/dist/types/schema/user.d.ts +85 -85
- package/dist/types/server.d.ts +117 -111
- package/dist/types/settings/email.d.ts +14 -14
- package/dist/types/settings/index.d.ts +195 -187
- package/dist/types/shared/clients.d.ts +46 -46
- package/dist/types/shared/email.d.ts +34 -34
- package/dist/types/shared/env.d.ts +47 -44
- package/dist/types/shared/error.d.ts +15 -15
- package/dist/types/shared/http.d.ts +22 -21
- package/dist/types/shared/password.d.ts +19 -19
- package/dist/types/shared/rootpath.d.ts +2 -2
- package/dist/types/shared/signin.d.ts +31 -31
- package/dist/types/shared/simple-fetch.d.ts +21 -21
- package/dist/types/shared/tokens.d.ts +24 -24
- package/dist/types/shared/validate.d.ts +22 -22
- package/dist/types/start.d.ts +1 -1
- package/dist/types/test.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +6 -6
- package/dist/types/websocket/manager.d.ts +99 -99
- package/dist/types/websocket/socket.io.d.ts +10 -10
- package/package.json +7 -4
- package/src/routes/data-schema-set.yaml +4 -0
- package/src/routes/data-set.yaml +5 -5
- package/src/routes/data-update.yaml +4 -4
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = exports.ForgotPasswordError = void 0;
|
|
13
|
-
const tokens_1 = require("../shared/tokens");
|
|
14
|
-
const acebase_core_1 = require("acebase-core");
|
|
15
|
-
const error_1 = require("../shared/error");
|
|
16
|
-
class ForgotPasswordError extends Error {
|
|
17
|
-
constructor(code, message) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.code = code;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ForgotPasswordError = ForgotPasswordError;
|
|
23
|
-
const addRoute = (env) => {
|
|
24
|
-
env.
|
|
25
|
-
var _a, _b, _c;
|
|
26
|
-
const details = req.body;
|
|
27
|
-
const LOG_ACTION = 'auth.forgot_password';
|
|
28
|
-
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, email: details.email };
|
|
29
|
-
try {
|
|
30
|
-
if (!env.config.email || typeof env.config.email.send !== 'function') {
|
|
31
|
-
throw new ForgotPasswordError('server_email_config', 'Server email settings have not been configured');
|
|
32
|
-
}
|
|
33
|
-
if (typeof details !== 'object' || typeof details.email !== 'string' || details.email.length === 0) {
|
|
34
|
-
throw new ForgotPasswordError('invalid_details', 'Invalid details');
|
|
35
|
-
}
|
|
36
|
-
const snaps = yield env.authRef.query().filter('email', '==', details.email).get();
|
|
37
|
-
if (snaps.length !== 1) {
|
|
38
|
-
throw new ForgotPasswordError('invalid_email', 'Email address not found, or duplicate entries found');
|
|
39
|
-
}
|
|
40
|
-
const snap = snaps[0];
|
|
41
|
-
const user = snap.val();
|
|
42
|
-
user.uid = snap.key;
|
|
43
|
-
user.password_reset_code = acebase_core_1.ID.generate();
|
|
44
|
-
// Request a password reset email to be sent:
|
|
45
|
-
const request = {
|
|
46
|
-
type: 'user_reset_password',
|
|
47
|
-
date: new Date(),
|
|
48
|
-
ip: req.ip,
|
|
49
|
-
resetCode: (0, tokens_1.createSignedPublicToken)({ uid: user.uid, code: user.password_reset_code }, env.tokenSalt),
|
|
50
|
-
user: {
|
|
51
|
-
email: user.email,
|
|
52
|
-
uid: user.uid,
|
|
53
|
-
username: user.username,
|
|
54
|
-
settings: user.settings,
|
|
55
|
-
displayName: user.display_name,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
yield snap.ref.update({ password_reset_code: user.password_reset_code });
|
|
59
|
-
yield env.config.email.send(request).catch(err => {
|
|
60
|
-
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { request }), err);
|
|
61
|
-
});
|
|
62
|
-
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
63
|
-
res.send('OK');
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
env.log.error(LOG_ACTION, err.code || 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_c = (err instanceof Error && err.message)) !== null && _c !== void 0 ? _c : err.toString() }));
|
|
67
|
-
if (err.code) {
|
|
68
|
-
(0, error_1.sendBadRequestError)(res, err);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
(0, error_1.sendUnexpectedError)(res, err);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
};
|
|
76
|
-
exports.addRoute = addRoute;
|
|
77
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = exports.ForgotPasswordError = void 0;
|
|
13
|
+
const tokens_1 = require("../shared/tokens");
|
|
14
|
+
const acebase_core_1 = require("acebase-core");
|
|
15
|
+
const error_1 = require("../shared/error");
|
|
16
|
+
class ForgotPasswordError extends Error {
|
|
17
|
+
constructor(code, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ForgotPasswordError = ForgotPasswordError;
|
|
23
|
+
const addRoute = (env) => {
|
|
24
|
+
env.router.post(`/auth/${env.db.name}/forgot_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const details = req.body;
|
|
27
|
+
const LOG_ACTION = 'auth.forgot_password';
|
|
28
|
+
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, email: details.email };
|
|
29
|
+
try {
|
|
30
|
+
if (!env.config.email || typeof env.config.email.send !== 'function') {
|
|
31
|
+
throw new ForgotPasswordError('server_email_config', 'Server email settings have not been configured');
|
|
32
|
+
}
|
|
33
|
+
if (typeof details !== 'object' || typeof details.email !== 'string' || details.email.length === 0) {
|
|
34
|
+
throw new ForgotPasswordError('invalid_details', 'Invalid details');
|
|
35
|
+
}
|
|
36
|
+
const snaps = yield env.authRef.query().filter('email', '==', details.email).get();
|
|
37
|
+
if (snaps.length !== 1) {
|
|
38
|
+
throw new ForgotPasswordError('invalid_email', 'Email address not found, or duplicate entries found');
|
|
39
|
+
}
|
|
40
|
+
const snap = snaps[0];
|
|
41
|
+
const user = snap.val();
|
|
42
|
+
user.uid = snap.key;
|
|
43
|
+
user.password_reset_code = acebase_core_1.ID.generate();
|
|
44
|
+
// Request a password reset email to be sent:
|
|
45
|
+
const request = {
|
|
46
|
+
type: 'user_reset_password',
|
|
47
|
+
date: new Date(),
|
|
48
|
+
ip: req.ip,
|
|
49
|
+
resetCode: (0, tokens_1.createSignedPublicToken)({ uid: user.uid, code: user.password_reset_code }, env.tokenSalt),
|
|
50
|
+
user: {
|
|
51
|
+
email: user.email,
|
|
52
|
+
uid: user.uid,
|
|
53
|
+
username: user.username,
|
|
54
|
+
settings: user.settings,
|
|
55
|
+
displayName: user.display_name,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
yield snap.ref.update({ password_reset_code: user.password_reset_code });
|
|
59
|
+
yield env.config.email.send(request).catch(err => {
|
|
60
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { request }), err);
|
|
61
|
+
});
|
|
62
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
63
|
+
res.send('OK');
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
env.log.error(LOG_ACTION, err.code || 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_c = (err instanceof Error && err.message)) !== null && _c !== void 0 ? _c : err.toString() }));
|
|
67
|
+
if (err.code) {
|
|
68
|
+
(0, error_1.sendBadRequestError)(res, err);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
(0, error_1.sendUnexpectedError)(res, err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
exports.addRoute = addRoute;
|
|
77
|
+
exports.default = exports.addRoute;
|
|
78
78
|
//# sourceMappingURL=auth-forgot-password.js.map
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = exports.ResetPasswordError = void 0;
|
|
13
|
-
const tokens_1 = require("../shared/tokens");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const password_1 = require("../shared/password");
|
|
16
|
-
class ResetPasswordError extends Error {
|
|
17
|
-
constructor(code, message) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.code = code;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ResetPasswordError = ResetPasswordError;
|
|
23
|
-
/**
|
|
24
|
-
* Adds the reset_password route and returns the reset function that can be used to manually reset a password
|
|
25
|
-
* @param env environment
|
|
26
|
-
* @returns returns the reset function
|
|
27
|
-
*/
|
|
28
|
-
const addRoute = (env) => {
|
|
29
|
-
const resetPassword = (clientIp, code, newPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
var _a;
|
|
31
|
-
const verification = (() => {
|
|
32
|
-
try {
|
|
33
|
-
return (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
throw new ResetPasswordError('invalid_code', err.message);
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
const snap = yield env.authRef.child(verification.uid).get();
|
|
40
|
-
if (!snap.exists()) {
|
|
41
|
-
throw new ResetPasswordError('unknown_user', 'Uknown user');
|
|
42
|
-
}
|
|
43
|
-
const user = snap.val();
|
|
44
|
-
user.uid = snap.key;
|
|
45
|
-
if (user.password_reset_code !== verification.code) {
|
|
46
|
-
throw new ResetPasswordError('invalid_code', 'Invalid code');
|
|
47
|
-
}
|
|
48
|
-
if (newPassword.length < 8 || newPassword.includes(' ')) {
|
|
49
|
-
throw new ResetPasswordError('password_requirement_mismatch', 'Password must be at least 8 characters, and cannot contain spaces');
|
|
50
|
-
}
|
|
51
|
-
// Ok to change password
|
|
52
|
-
const pwd = (0, password_1.createPasswordHash)(newPassword);
|
|
53
|
-
yield snap.ref.update({
|
|
54
|
-
password: pwd.hash,
|
|
55
|
-
password_salt: pwd.salt,
|
|
56
|
-
password_reset_code: null,
|
|
57
|
-
});
|
|
58
|
-
// Send confirmation email
|
|
59
|
-
const request = {
|
|
60
|
-
type: 'user_reset_password_success',
|
|
61
|
-
date: new Date(),
|
|
62
|
-
ip: clientIp,
|
|
63
|
-
user: {
|
|
64
|
-
uid: user.uid,
|
|
65
|
-
email: user.email,
|
|
66
|
-
username: user.username,
|
|
67
|
-
displayName: user.display_name,
|
|
68
|
-
settings: user.settings,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
(_a = env.config.email) === null || _a === void 0 ? void 0 : _a.send(request);
|
|
72
|
-
return user;
|
|
73
|
-
});
|
|
74
|
-
env.
|
|
75
|
-
var _b, _c, _d, _e;
|
|
76
|
-
const details = req.body;
|
|
77
|
-
const LOG_ACTION = 'auth.reset_password';
|
|
78
|
-
const LOG_DETAILS = { ip: req.ip, uid: (_c = (_b = req.user) === null || _b === void 0 ? void 0 : _b.uid) !== null && _c !== void 0 ? _c : null };
|
|
79
|
-
try {
|
|
80
|
-
const user = yield resetPassword(req.ip, details.code, details.password);
|
|
81
|
-
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { reset_uid: user.uid }));
|
|
82
|
-
res.send('OK');
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
env.log.error(LOG_ACTION, (_d = err.code) !== null && _d !== void 0 ? _d : 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_e = (err instanceof Error && err.message)) !== null && _e !== void 0 ? _e : err.toString() }));
|
|
86
|
-
if (err.code) {
|
|
87
|
-
(0, error_1.sendBadRequestError)(res, err);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
(0, error_1.sendUnexpectedError)(res, err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}));
|
|
94
|
-
return resetPassword;
|
|
95
|
-
};
|
|
96
|
-
exports.addRoute = addRoute;
|
|
97
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = exports.ResetPasswordError = void 0;
|
|
13
|
+
const tokens_1 = require("../shared/tokens");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const password_1 = require("../shared/password");
|
|
16
|
+
class ResetPasswordError extends Error {
|
|
17
|
+
constructor(code, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ResetPasswordError = ResetPasswordError;
|
|
23
|
+
/**
|
|
24
|
+
* Adds the reset_password route and returns the reset function that can be used to manually reset a password
|
|
25
|
+
* @param env environment
|
|
26
|
+
* @returns returns the reset function
|
|
27
|
+
*/
|
|
28
|
+
const addRoute = (env) => {
|
|
29
|
+
const resetPassword = (clientIp, code, newPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
var _a;
|
|
31
|
+
const verification = (() => {
|
|
32
|
+
try {
|
|
33
|
+
return (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw new ResetPasswordError('invalid_code', err.message);
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
const snap = yield env.authRef.child(verification.uid).get();
|
|
40
|
+
if (!snap.exists()) {
|
|
41
|
+
throw new ResetPasswordError('unknown_user', 'Uknown user');
|
|
42
|
+
}
|
|
43
|
+
const user = snap.val();
|
|
44
|
+
user.uid = snap.key;
|
|
45
|
+
if (user.password_reset_code !== verification.code) {
|
|
46
|
+
throw new ResetPasswordError('invalid_code', 'Invalid code');
|
|
47
|
+
}
|
|
48
|
+
if (newPassword.length < 8 || newPassword.includes(' ')) {
|
|
49
|
+
throw new ResetPasswordError('password_requirement_mismatch', 'Password must be at least 8 characters, and cannot contain spaces');
|
|
50
|
+
}
|
|
51
|
+
// Ok to change password
|
|
52
|
+
const pwd = (0, password_1.createPasswordHash)(newPassword);
|
|
53
|
+
yield snap.ref.update({
|
|
54
|
+
password: pwd.hash,
|
|
55
|
+
password_salt: pwd.salt,
|
|
56
|
+
password_reset_code: null,
|
|
57
|
+
});
|
|
58
|
+
// Send confirmation email
|
|
59
|
+
const request = {
|
|
60
|
+
type: 'user_reset_password_success',
|
|
61
|
+
date: new Date(),
|
|
62
|
+
ip: clientIp,
|
|
63
|
+
user: {
|
|
64
|
+
uid: user.uid,
|
|
65
|
+
email: user.email,
|
|
66
|
+
username: user.username,
|
|
67
|
+
displayName: user.display_name,
|
|
68
|
+
settings: user.settings,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
(_a = env.config.email) === null || _a === void 0 ? void 0 : _a.send(request);
|
|
72
|
+
return user;
|
|
73
|
+
});
|
|
74
|
+
env.router.post(`/auth/${env.db.name}/reset_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
var _b, _c, _d, _e;
|
|
76
|
+
const details = req.body;
|
|
77
|
+
const LOG_ACTION = 'auth.reset_password';
|
|
78
|
+
const LOG_DETAILS = { ip: req.ip, uid: (_c = (_b = req.user) === null || _b === void 0 ? void 0 : _b.uid) !== null && _c !== void 0 ? _c : null };
|
|
79
|
+
try {
|
|
80
|
+
const user = yield resetPassword(req.ip, details.code, details.password);
|
|
81
|
+
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { reset_uid: user.uid }));
|
|
82
|
+
res.send('OK');
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
env.log.error(LOG_ACTION, (_d = err.code) !== null && _d !== void 0 ? _d : 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_e = (err instanceof Error && err.message)) !== null && _e !== void 0 ? _e : err.toString() }));
|
|
86
|
+
if (err.code) {
|
|
87
|
+
(0, error_1.sendBadRequestError)(res, err);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
(0, error_1.sendUnexpectedError)(res, err);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
return resetPassword;
|
|
95
|
+
};
|
|
96
|
+
exports.addRoute = addRoute;
|
|
97
|
+
exports.default = exports.addRoute;
|
|
98
98
|
//# sourceMappingURL=auth-reset-password.js.map
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const user_1 = require("../schema/user");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const tokens_1 = require("../shared/tokens");
|
|
16
|
-
const signin_1 = require("../shared/signin");
|
|
17
|
-
const addRoute = (env) => {
|
|
18
|
-
if (!env.config.auth.enabled) {
|
|
19
|
-
throw new Error('Authentication not enabled in the server settings');
|
|
20
|
-
}
|
|
21
|
-
env.
|
|
22
|
-
const details = req.body;
|
|
23
|
-
const clientId = details.client_id || null; // NEW in AceBaseClient v0.9.4
|
|
24
|
-
try {
|
|
25
|
-
const user = yield (0, signin_1.signIn)(details, env, req);
|
|
26
|
-
if (typeof clientId === 'string' && env.clients.has(clientId)) {
|
|
27
|
-
const client = env.clients.get(clientId);
|
|
28
|
-
client.user = user; // Bind user to client socket
|
|
29
|
-
}
|
|
30
|
-
res.send({
|
|
31
|
-
access_token: (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt),
|
|
32
|
-
user: (0, user_1.getPublicAccountDetails)(user),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
if (typeof err.code === 'string') {
|
|
37
|
-
// Authentication error
|
|
38
|
-
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
39
|
-
}
|
|
40
|
-
// Unexpected error
|
|
41
|
-
return (0, error_1.sendUnexpectedError)(res, err);
|
|
42
|
-
}
|
|
43
|
-
}));
|
|
44
|
-
};
|
|
45
|
-
exports.addRoute = addRoute;
|
|
46
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const user_1 = require("../schema/user");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const tokens_1 = require("../shared/tokens");
|
|
16
|
+
const signin_1 = require("../shared/signin");
|
|
17
|
+
const addRoute = (env) => {
|
|
18
|
+
if (!env.config.auth.enabled) {
|
|
19
|
+
throw new Error('Authentication not enabled in the server settings');
|
|
20
|
+
}
|
|
21
|
+
env.router.post(`/auth/${env.db.name}/signin`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const details = req.body;
|
|
23
|
+
const clientId = details.client_id || null; // NEW in AceBaseClient v0.9.4
|
|
24
|
+
try {
|
|
25
|
+
const user = yield (0, signin_1.signIn)(details, env, req);
|
|
26
|
+
if (typeof clientId === 'string' && env.clients.has(clientId)) {
|
|
27
|
+
const client = env.clients.get(clientId);
|
|
28
|
+
client.user = user; // Bind user to client socket
|
|
29
|
+
}
|
|
30
|
+
res.send({
|
|
31
|
+
access_token: (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt),
|
|
32
|
+
user: (0, user_1.getPublicAccountDetails)(user),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (typeof err.code === 'string') {
|
|
37
|
+
// Authentication error
|
|
38
|
+
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
39
|
+
}
|
|
40
|
+
// Unexpected error
|
|
41
|
+
return (0, error_1.sendUnexpectedError)(res, err);
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
exports.addRoute = addRoute;
|
|
46
|
+
exports.default = exports.addRoute;
|
|
47
47
|
//# sourceMappingURL=auth-signin.js.map
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const error_1 = require("../shared/error");
|
|
14
|
-
const addRoute = (env) => {
|
|
15
|
-
env.
|
|
16
|
-
var _a, _b, _c;
|
|
17
|
-
const LOG_ACTION = 'auth.signout';
|
|
18
|
-
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null };
|
|
19
|
-
try {
|
|
20
|
-
if (req.user) {
|
|
21
|
-
const client = typeof req.body.client_id === 'string' ? env.clients.get(req.body.client_id) : null; // NEW in AceBaseClient v0.9.4
|
|
22
|
-
if (client) {
|
|
23
|
-
// Remove user binding from client socket
|
|
24
|
-
client.user = null;
|
|
25
|
-
}
|
|
26
|
-
const signOutEverywhere = typeof req.body === 'object' && req.body.everywhere === true; // NEW in AceBaseClient v0.9.14
|
|
27
|
-
if (signOutEverywhere) {
|
|
28
|
-
// Remove token from cache
|
|
29
|
-
env.authCache.remove(req.user.uid);
|
|
30
|
-
// Remove user binding from all clients signed in with current user
|
|
31
|
-
for (const client of env.clients.values()) {
|
|
32
|
-
if (((_c = client.user) === null || _c === void 0 ? void 0 : _c.uid) === req.user.uid) {
|
|
33
|
-
client.user = null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Remove token from user's auth node
|
|
38
|
-
yield env.authRef.child(req.user.uid).transaction(snap => {
|
|
39
|
-
if (!snap.exists()) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const user = snap.val();
|
|
43
|
-
if (signOutEverywhere) {
|
|
44
|
-
user.access_token = null;
|
|
45
|
-
}
|
|
46
|
-
user.last_signout = new Date();
|
|
47
|
-
user.last_signout_ip = req.ip;
|
|
48
|
-
return user;
|
|
49
|
-
});
|
|
50
|
-
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
51
|
-
}
|
|
52
|
-
res.send('Bye!');
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
env.log.error(LOG_ACTION, 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: err instanceof Error ? err.message : err.toString() }));
|
|
56
|
-
(0, error_1.sendUnexpectedError)(res, err);
|
|
57
|
-
}
|
|
58
|
-
}));
|
|
59
|
-
};
|
|
60
|
-
exports.addRoute = addRoute;
|
|
61
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const error_1 = require("../shared/error");
|
|
14
|
+
const addRoute = (env) => {
|
|
15
|
+
env.router.post(`/auth/${env.db.name}/signout`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const LOG_ACTION = 'auth.signout';
|
|
18
|
+
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null };
|
|
19
|
+
try {
|
|
20
|
+
if (req.user) {
|
|
21
|
+
const client = typeof req.body.client_id === 'string' ? env.clients.get(req.body.client_id) : null; // NEW in AceBaseClient v0.9.4
|
|
22
|
+
if (client) {
|
|
23
|
+
// Remove user binding from client socket
|
|
24
|
+
client.user = null;
|
|
25
|
+
}
|
|
26
|
+
const signOutEverywhere = typeof req.body === 'object' && req.body.everywhere === true; // NEW in AceBaseClient v0.9.14
|
|
27
|
+
if (signOutEverywhere) {
|
|
28
|
+
// Remove token from cache
|
|
29
|
+
env.authCache.remove(req.user.uid);
|
|
30
|
+
// Remove user binding from all clients signed in with current user
|
|
31
|
+
for (const client of env.clients.values()) {
|
|
32
|
+
if (((_c = client.user) === null || _c === void 0 ? void 0 : _c.uid) === req.user.uid) {
|
|
33
|
+
client.user = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Remove token from user's auth node
|
|
38
|
+
yield env.authRef.child(req.user.uid).transaction(snap => {
|
|
39
|
+
if (!snap.exists()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const user = snap.val();
|
|
43
|
+
if (signOutEverywhere) {
|
|
44
|
+
user.access_token = null;
|
|
45
|
+
}
|
|
46
|
+
user.last_signout = new Date();
|
|
47
|
+
user.last_signout_ip = req.ip;
|
|
48
|
+
return user;
|
|
49
|
+
});
|
|
50
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
51
|
+
}
|
|
52
|
+
res.send('Bye!');
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
env.log.error(LOG_ACTION, 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: err instanceof Error ? err.message : err.toString() }));
|
|
56
|
+
(0, error_1.sendUnexpectedError)(res, err);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
exports.addRoute = addRoute;
|
|
61
|
+
exports.default = exports.addRoute;
|
|
62
62
|
//# sourceMappingURL=auth-signout.js.map
|