@paralect/hive 0.0.24 → 0.0.27
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/package.json +1 -1
- package/starter/src/app-config/index.js +2 -0
- package/starter/src/middlewares/isAuthorized.js +10 -1
- package/starter/src/resources/tokens/methods/storeToken.js +2 -1
- package/starter/src/resources/tokens/tokens.schema.js +1 -0
- package/starter/src/resources/users/endpoints/getCurrentUser.js +1 -3
- package/starter/src/resources/users/users.schema.js +1 -1
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const config = require('app-config');
|
|
1
2
|
const userService = require('db').services.users;
|
|
2
3
|
const tokenService = require('db').services.tokens;
|
|
3
4
|
|
|
@@ -5,11 +6,15 @@ const storeTokenToState = async (ctx) => {
|
|
|
5
6
|
let accessToken = ctx.cookies.get('access_token');
|
|
6
7
|
|
|
7
8
|
const { authorization } = ctx.headers;
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
if (!accessToken && authorization) {
|
|
10
11
|
accessToken = authorization.replace('Bearer', '').trim();
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
if (!accessToken && config._hive.authHeaderName && ctx.headers[config._hive.authHeaderName]) {
|
|
15
|
+
accessToken = ctx.headers[config._hive.authHeaderName];
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
ctx.state.accessToken = accessToken;
|
|
14
19
|
};
|
|
15
20
|
|
|
@@ -24,6 +29,10 @@ module.exports = async (ctx, next) => {
|
|
|
24
29
|
|
|
25
30
|
if (token) {
|
|
26
31
|
ctx.state.user = await userService.findOne({ _id: token.user._id });
|
|
32
|
+
|
|
33
|
+
if (token.metadata) {
|
|
34
|
+
ctx.state.user.authMetadata = token.metadata;
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
if (ctx.state.user) {
|
|
@@ -12,7 +12,7 @@ const generateSecureToken = async (tokenLength = 32) => {
|
|
|
12
12
|
return buf.toString('hex');
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
module.exports = async (ctx, { userId }) => {
|
|
15
|
+
module.exports = async (ctx, { userId, metadata = null }) => {
|
|
16
16
|
const token = await generateSecureToken();
|
|
17
17
|
const otp = await generateSecureToken();
|
|
18
18
|
|
|
@@ -22,6 +22,7 @@ module.exports = async (ctx, { userId }) => {
|
|
|
22
22
|
_id: userId,
|
|
23
23
|
},
|
|
24
24
|
otp,
|
|
25
|
+
...(metadata ? { metadata } : {})
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
setCookie(ctx, { name: 'access_token', value: token });
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const Joi = require("joi");
|
|
2
|
-
const userService = require('db').services.users;
|
|
3
2
|
|
|
4
3
|
module.exports.handler = async (ctx) => {
|
|
5
|
-
|
|
6
|
-
ctx.body = user;
|
|
4
|
+
ctx.body = ctx.state.user;
|
|
7
5
|
};
|
|
8
6
|
|
|
9
7
|
module.exports.middlewares = [require('middlewares/isAuthorized')];
|