@paralect/hive 0.0.23 → 0.0.25

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paralect/hive",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,6 +24,10 @@ module.exports = async (ctx, next) => {
24
24
 
25
25
  if (token) {
26
26
  ctx.state.user = await userService.findOne({ _id: token.user._id });
27
+
28
+ if (token.metadata) {
29
+ ctx.state.user.authMetadata = token.metadata;
30
+ }
27
31
  }
28
32
 
29
33
  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 });
@@ -9,4 +9,5 @@ module.exports = Joi.object({
9
9
  }).required(),
10
10
  token: Joi.string().required(),
11
11
  otp: Joi.string().allow(null).allow(''),
12
+ metadata: Joi.object({}).optional()
12
13
  });
@@ -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
- const user = await userService.findOne({ _id: ctx.state.user._id });
6
- ctx.body = user;
4
+ ctx.body = ctx.state.user;
7
5
  };
8
6
 
9
7
  module.exports.middlewares = [require('middlewares/isAuthorized')];
@@ -84,7 +84,9 @@ module.exports = (server) => {
84
84
  io.on("connection", (client) => {
85
85
  client.on("subscribe", (roomId) => {
86
86
  const { userId } = client.handshake.data;
87
- const hasAccessToRoom = checkAccessToRoom(roomId, { userId });
87
+ // const hasAccessToRoom = checkAccessToRoom(roomId, { userId });
88
+
89
+ const hasAccessToRoom = true;
88
90
 
89
91
  if (hasAccessToRoom) {
90
92
  client.join(roomId);