adaptic-backend 1.0.327 → 1.0.329

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.
Files changed (57) hide show
  1. package/Account.cjs +1 -1
  2. package/Action.cjs +1 -1
  3. package/Alert.cjs +1 -1
  4. package/Allocation.cjs +1 -1
  5. package/AlpacaAccount.cjs +1 -1
  6. package/Asset.cjs +1 -1
  7. package/Authenticator.cjs +1 -1
  8. package/Customer.cjs +1 -1
  9. package/EconomicEvent.cjs +1 -1
  10. package/MarketSentiment.cjs +1 -1
  11. package/NewsArticle.cjs +1 -1
  12. package/NewsArticleAssetSentiment.cjs +1 -1
  13. package/ScheduledOptionOrder.cjs +1 -1
  14. package/Session.cjs +1 -1
  15. package/Trade.cjs +1 -1
  16. package/User.cjs +1 -1
  17. package/VerificationToken.cjs +1 -1
  18. package/esm/Account.js.map +1 -1
  19. package/esm/Account.mjs +1 -1
  20. package/esm/Action.js.map +1 -1
  21. package/esm/Action.mjs +1 -1
  22. package/esm/Alert.js.map +1 -1
  23. package/esm/Alert.mjs +1 -1
  24. package/esm/Allocation.js.map +1 -1
  25. package/esm/Allocation.mjs +1 -1
  26. package/esm/AlpacaAccount.js.map +1 -1
  27. package/esm/AlpacaAccount.mjs +1 -1
  28. package/esm/Asset.js.map +1 -1
  29. package/esm/Asset.mjs +1 -1
  30. package/esm/Authenticator.js.map +1 -1
  31. package/esm/Authenticator.mjs +1 -1
  32. package/esm/Customer.js.map +1 -1
  33. package/esm/Customer.mjs +1 -1
  34. package/esm/EconomicEvent.js.map +1 -1
  35. package/esm/EconomicEvent.mjs +1 -1
  36. package/esm/MarketSentiment.js.map +1 -1
  37. package/esm/MarketSentiment.mjs +1 -1
  38. package/esm/NewsArticle.js.map +1 -1
  39. package/esm/NewsArticle.mjs +1 -1
  40. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  41. package/esm/NewsArticleAssetSentiment.mjs +1 -1
  42. package/esm/ScheduledOptionOrder.js.map +1 -1
  43. package/esm/ScheduledOptionOrder.mjs +1 -1
  44. package/esm/Session.js.map +1 -1
  45. package/esm/Session.mjs +1 -1
  46. package/esm/Trade.js.map +1 -1
  47. package/esm/Trade.mjs +1 -1
  48. package/esm/User.js.map +1 -1
  49. package/esm/User.mjs +1 -1
  50. package/esm/VerificationToken.js.map +1 -1
  51. package/esm/VerificationToken.mjs +1 -1
  52. package/esm/middleware/auth.d.ts +1 -1
  53. package/esm/middleware/auth.d.ts.map +1 -1
  54. package/esm/middleware/auth.js.map +1 -1
  55. package/esm/middleware/auth.mjs +10 -1
  56. package/package.json +1 -1
  57. package/server.cjs +37 -15
package/server.cjs CHANGED
@@ -119,19 +119,31 @@ const startServer = async () => {
119
119
  await server.start();
120
120
  app.use('/graphql', (0, cors_1.default)(), body_parser_1.default.json(), (0, express4_1.expressMiddleware)(server, {
121
121
  context: async ({ req }) => {
122
- var _a;
123
122
  console.log('Received headers:', req.headers);
124
123
  console.log('Authorization header:', req.headers.authorization);
125
- const token = ((_a = req.headers.authorization) === null || _a === void 0 ? void 0 : _a.split(' ')[1]) || '';
124
+ // Extract token from Authorization header
125
+ const authHeader = req.headers.authorization || '';
126
+ // Only try to verify token if it's in proper Bearer format
127
+ const token = authHeader.startsWith('Bearer ') ? authHeader.split(' ')[1] : '';
126
128
  let user = null;
127
129
  if (token) {
128
- try {
129
- user = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
130
+ // Check if token is a Google OAuth token (starts with ya29.)
131
+ if (token.startsWith('ya29.')) {
132
+ // For Google OAuth tokens, we should validate differently or pass them through
133
+ // This is a temporary solution - ideally you should verify with Google's OAuth API
134
+ console.log('Detected Google OAuth token, skipping JWT verification');
135
+ user = { provider: 'google', token };
130
136
  }
131
- catch (e) {
132
- console.error('JWT verification failed:', e);
133
- console.error('Received token:', token);
134
- return { prisma: prismaClient_1.default, req, authError: 'Invalid token' };
137
+ else {
138
+ // For regular JWT tokens, verify as before
139
+ try {
140
+ user = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
141
+ }
142
+ catch (e) {
143
+ console.error('JWT verification failed:', e);
144
+ console.error('Received token:', token);
145
+ return { prisma: prismaClient_1.default, req, authError: 'Invalid token' };
146
+ }
135
147
  }
136
148
  }
137
149
  return { prisma: prismaClient_1.default, req, user };
@@ -153,16 +165,26 @@ const startServer = async () => {
153
165
  (0, ws_2.useServer)({
154
166
  schema,
155
167
  context: async (ctx, msg, args) => {
156
- var _a, _b;
157
- const token = ((_b = (_a = ctx.connectionParams) === null || _a === void 0 ? void 0 : _a.authorization) === null || _b === void 0 ? void 0 : _b.split(' ')[1]) || '';
168
+ var _a;
169
+ const authHeader = ((_a = ctx.connectionParams) === null || _a === void 0 ? void 0 : _a.authorization) || '';
170
+ const token = authHeader.startsWith('Bearer ') ? authHeader.split(' ')[1] : '';
158
171
  let user = null;
159
172
  if (token) {
160
- try {
161
- user = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
173
+ // Check if token is a Google OAuth token (starts with ya29.)
174
+ if (token.startsWith('ya29.')) {
175
+ // For Google OAuth tokens, we should validate differently or pass them through
176
+ console.log('Detected Google OAuth token in WebSocket, skipping JWT verification');
177
+ user = { provider: 'google', token };
162
178
  }
163
- catch (e) {
164
- console.error('JWT verification failed:', e);
165
- return { prisma: prismaClient_1.default, authError: 'Invalid token' };
179
+ else {
180
+ // For regular JWT tokens, verify as before
181
+ try {
182
+ user = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
183
+ }
184
+ catch (e) {
185
+ console.error('JWT verification failed:', e);
186
+ return { prisma: prismaClient_1.default, authError: 'Invalid token' };
187
+ }
166
188
  }
167
189
  }
168
190
  return { prisma: prismaClient_1.default, user };