StitchClient
can longer be constructed directly. Instead, StitchClientFactory
has been introduced to asynchronously perform any initialization steps needed to create a StitchClient
. StitchClientFactory
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.
// 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.
StitchClient
s (with different associated applications).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:
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.findOne()
method to the MongoDB service class.StitchClientFactory
.