propro-utils 1.4.97 → 1.4.98

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/server/index.js +20 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.97",
3
+ "version": "1.4.98",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -288,10 +288,13 @@ class AuthMiddleware {
288
288
 
289
289
  handleAvatarUpdate = async (req, res) => {
290
290
  try {
291
+ if (!req.file) {
292
+ return res.status(400).json({ error: 'No file uploaded' });
293
+ }
294
+
291
295
  const response = await this.proxyToAuthServer(
292
296
  req,
293
- '/api/v1/accounts/avatar',
294
- req.file
297
+ '/api/v1/accounts/avatar'
295
298
  );
296
299
  res.status(response.status).json(response.data);
297
300
  } catch (error) {
@@ -306,7 +309,7 @@ class AuthMiddleware {
306
309
  );
307
310
  };
308
311
 
309
- proxyToAuthServer = async (req, path, body) => {
312
+ proxyToAuthServer = async (req, path) => {
310
313
  let accessToken = null;
311
314
  if (this.pathRequiresAccessToken(path)) {
312
315
  console.log('path requires access token');
@@ -316,8 +319,13 @@ class AuthMiddleware {
316
319
  }
317
320
  }
318
321
 
322
+ const formData = new FormData();
323
+ if (req.file) {
324
+ formData.append('file', req.file.buffer, file.originalname);
325
+ }
326
+
319
327
  let headers = {
320
- 'Content-Type': 'application/json',
328
+ ...formData.getHeaders(),
321
329
  };
322
330
 
323
331
  if (accessToken) {
@@ -330,28 +338,19 @@ class AuthMiddleware {
330
338
  formattedAuthUrl = `${formattedAuthUrl}&clientId=${this.options.clientId}&redirectUri=${this.options.redirectUri}`;
331
339
  }
332
340
 
333
- const formData = new FormData();
334
- if (req.file) {
335
- formData.append('file', req.file.buffer, {
336
- filename: req.file.originalname,
337
- contentType: req.file.mimetype,
338
- });
339
- }
340
-
341
341
  console.log('formattedAuthUrl:', formattedAuthUrl);
342
342
  console.log('req.method:', req.method);
343
- console.log('req.body:', req.body);
344
- console.log('req.file:', req.file);
345
- console.log('formData:', JSON.stringify(formData));
346
- console.log('headers:', JSON.stringify(headers));
343
+ console.log('file:', file);
344
+ console.log('formData:', formData);
345
+ console.log('headers:', headers);
346
+
347
+ const data = file ? formData : req.body;
348
+
347
349
  return axios({
348
350
  method: req.method,
349
351
  url: `${formattedAuthUrl}${path}`,
350
- data: req.body,
351
- headers: {
352
- ...headers,
353
- ...formData.getHeaders(),
354
- },
352
+ data: data,
353
+ headers: headers,
355
354
  });
356
355
  };
357
356