(token)
| 27 | } |
| 28 | |
| 29 | async authenticateToken(token) { |
| 30 | if (!token) { |
| 31 | throw new Error("Token is required"); |
| 32 | } |
| 33 | |
| 34 | const blacklisted = await db.TokenBlacklist.findOne({ where: { token } }); |
| 35 | if (blacklisted) { |
| 36 | throw new Error("Unauthorized access"); |
| 37 | } |
| 38 | |
| 39 | let decoded; |
| 40 | try { |
| 41 | decoded = jwt.verify(token, settings.encryptionKey); |
| 42 | } catch (error) { |
| 43 | decoded = jwt.verify(token, settings.secret); |
| 44 | } |
| 45 | |
| 46 | if (!decoded?.id) { |
| 47 | throw new Error("Unauthorized access"); |
| 48 | } |
| 49 | |
| 50 | const user = await db.User.findByPk(decoded.id); |
| 51 | if (!user) { |
| 52 | throw new Error("Unauthorized access"); |
| 53 | } |
| 54 | |
| 55 | return user; |
| 56 | } |
| 57 | |
| 58 | async canJoinConversation(userId, conversationId, teamId = null) { |
| 59 | if (!userId || !conversationId) { |
no outgoing calls
no test coverage detected