Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'uppyAuthToken') #5688

Open
2 tasks done
keery opened this issue Mar 14, 2025 · 0 comments
Open
2 tasks done

Cannot read properties of undefined (reading 'uppyAuthToken') #5688

keery opened this issue Mar 14, 2025 · 0 comments
Labels

Comments

@keery
Copy link

keery commented Mar 14, 2025

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

No response

Steps to reproduce

Hi,

First of all I have been using Uppy for years and thank you so much for this wonderful tool.

I am using Uppy with React and Companion with the following versions

// client
    "@uppy/core": "^4.4.3",
    "@uppy/dashboard": "^4.0.3",
    "@uppy/google-drive-picker": "^0.3.3",
// server
   "@uppy/companion": "^5.5.2",

My companion service

import { Injectable, OnModuleInit, Logger } from '@nestjs/common'
import companion = require('@uppy/companion')
import fs from 'fs'

@Injectable()
export class UppyService implements OnModuleInit {
  private logger = new Logger('UppyService')
  private companionServer

  onModuleInit() {
    this.initializeCompanionServer()
  }

  async handleCompanion(req, res) {
    return this.companionServer.app.handle(req, res)
  }

  private initializeCompanionServer() {
    const dir = './tmp'

    if (!fs.existsSync(dir)) {
      fs.mkdirSync(dir)
    }

    this.logger.verbose(`Initializing Companion Server.`)
    const options = {
      providerOptions: {
        instagram: {
          key: process.env.INSTAGRAM_KEY,
          secret: process.env.INSTAGRAM_SECRET,
        },
        drive: {
          key: process.env.GOOGLE_DRIVE_KEY,
          secret: process.env.GOOGLE_DRIVE_SECRET,
        },
        facebook: {
          key: process.env.FACEBOOK_KEY,
          secret: process.env.FACEBOOK_SECRET,
        },
        dropbox: {
          key: process.env.DROPBOX_KEY,
          secret: process.env.DROPBOX_SECRET,
        },
      },
      server: {
        host: process.env.HOST,
        protocol: process.env.PROTOCOL,
        path: '/api/image/companion',
      },
      uploadUrls: ['/api/image/upload'],
      filePath: 'tmp/',
      secret: process.env.SESSION_SECRET,
      debug: true,
      corsOrigins: true,
      enableGooglePickerEndpoint: true,
    }

    this.companionServer = companion.app(options)
  }
}


My uppy instance client side

const instance = new Uppy({
      id,
      autoProceed: true,
      locale: "en",
      debug: true,
      logger: debugLogger,
      allowMultipleUploads: false,
      restrictions: {
        maxFileSize: MAX_FILE_SIZE,
        maxNumberOfFiles: 1,
        allowedFileTypes: ["image/*"],
      },
    })
      .use(XHRUpload, {
        endpoint: `${process.env.NEXT_PUBLIC_API_URL}/image/upload`,
      })
      .use(Webcam)
      .use(Dropbox, {
        companionUrl: COMPANION_URL,
      })
      .use(Facebook, {
        companionUrl: COMPANION_URL,
      })
      .use(GoogleDrivePicker, {
        companionUrl: COMPANION_URL,
        clientId: process.env.NEXT_PUBLIC_GOOGLE_DRIVE_CLIENT_ID,
        apiKey: process.env.NEXT_PUBLIC_GOOGLE_DRIVE_API_KEY,
        appId: process.env.NEXT_PUBLIC_GOOGLE_DRIVE_APP_ID,
      })
      .on("restriction-failed", (event) => {
        if (event.size > MAX_FILE_SIZE) {
          errorToast(t("fileTooBig", { max: MAX_FILE_SIZE * 0.000001 }));
        }
      })
      .on("upload-success", (file, response) => {
        client
          .get(`/image/tmp/get/${response.body.url}`, {
            responseType: "blob",
          })
          .then((res) => {
            const reader = new FileReader();
            reader.onload = function (e) {
              if (onSuccess) onSuccess();
            };
            reader.readAsDataURL(res.data);
          })
          .catch(() => {
            if (onError) onError();
            instance.cancelAll();
            errorToast(t("uploadFailed"));
          });
      });

Expected behavior

I should be able to authenticate OAuth provider and upload files from them

Actual behavior

Every http calls to API_URL/companion/PROVIDER/** are throwing this error blocking every interaction with providers

I have the issue using any provider, Google Drive, DropBox, etc

TypeError: Cannot read properties of undefined (reading 'uppyAuthToken')

@keery keery added the Bug label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant