MongoDB Stitch JavaScript SDK Release - 3.0.0

49 views
Skip to first unread message

MongoDB Stitch Announcements

unread,
Jan 29, 2018, 2:52:45 PM1/29/18
to MongoDB Stitch Announcements
Hello all,

We've released the 3.0.0 version of the Stitch JavaScript SDK. Below are the changes:

3.0.0

Usage of StitchClient

StitchClient can longer be constructed directly. Instead, StitchClientFactory has been introduced to asynchronously perform any initialization steps needed to create a StitchClientStitchClientFactory has a function called create that will return a Promise that will resolve with a StitchClient after initialization. The resolved client should be used for the lifetime of the application.

Migration Path

// old, 2.x.x usage
import { StitchClient } from 'mongodb-stitch';
const stitchClient = new StitchClient('<app-id>');
stitchClient.login().then(authedId => console.log(authedId));
// app initialization code

// new, 3.x.x usage
import { StitchClientFactory } from 'mongodb-stitch';
const stitchClientPromise = StitchClientFactory.create('<app-id>');
stitchClientPromise.then(stitchClient => stitchClient.login().then(authedId => {
	console.log(authedId);
	initializeApp(stitchClient);
}));

Since the StitchClient is only available after the Promise resolves, initialization of an app should be deferred until this time and the client reference should be passed to some initialization component/function.

NOTE: Attempting to construct a StitchClient without using StitchClientFactory will result in an error being thrown.

Multiple Apps

  • Add support for multiple StitchClients (with different associated applications).

Authentication

Previously, logging in with a provider while already logging caused no log in to happen which proved to be confusing. These new semantics are in effect:

  • Authenticating multiple times with anonymous authentication while already authenticated anonymously does nothing and returns the current user ID.
  • Authenticating with any provider but anonymous will log out the current user and then log in with the new provider.
  • Add isAuthenticated() method to the StitchClient class. This method should be used to check if any authentication work needs to happen. It returns a boolean declaring whether or not the current client is authenticated.
  • Add Client API key management. This feature allows one to create API keys linked to the currently logged in user. This does not work on anonymous users or Server API key users.

Services

  • Add missing findOne() method to the MongoDB service class.

Miscellaneous

  • Expose BSON module directly alongside StitchClientFactory.

Please let us know if have any questions, feedback, or notice any issues on the MongoDB Stitch Users Group.
Reply all
Reply to author
Forward
0 new messages