mongodb / stitch-js-sdk

MongoDB Stitch JavaScript SDK
Apache License 2.0
113 stars 67 forks source link

Unable to authenticate using FacebookRedirectCredential #372

Open jpreecedev opened 4 years ago

jpreecedev commented 4 years ago

I'm just getting started with MongoDB stitch so apologies if I am making a silly mistake.

I would like to create a simple login form to restrict access to a dashboard. I would like to use Google and Facebook auth.

I am using mongodb-stitch-browser-sdk@4.8.0 and basically using the example as per the docs to prove this out.

  const client = Stitch.initializeDefaultAppClient('MYPRIVATEAPP-aaaaa')

  const db = client
    .getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')
    .db('MYPRIVATEAPP')

  const credential = new FacebookRedirectCredential()

  client.auth
    .loginWithCredential(credential)
    .then(() => {
      return db
        .collection('users')
        .updateOne({ ownerId: client?.auth?.user?.id }, { $set: { number: 42 } }, { upsert: true })
    })
    .then(() => {
      return db
        .collection('users')
        .find({ ownerId: client?.auth?.user?.id }, { limit: 100 })
        .asArray()
    })
    .then((docs: any) => {
      console.log('Found docs', docs)
      console.log('[MongoDB Stitch] Connected to Stitch')
    })
    .catch((err: Error) => {
      console.error(err)
    })

The above code does not work. I get this error; TypeError: Cannot read property 'reusesExistingSession' of undefined

I've set up my apps in Facebook and Google and I've done this many times before so I'm sure I've done it right. I've enabled the auth providers in Mongo stitch, so is this a bug or am I missing something?

Thanks