Advanced
getOrCreateDocAndToken

getOrCreateDocAndToken

getOrCreateDocAndToken is a helper from our Javascript SDK (opens in a new tab) that can ensure a document with the given ID exists, and then returns a client token that can be used to connect to the document.

If a document ID is not provided, getOrCreateDocAndToken will automatically generate a doc and associated docID for you.

Calling getOrCreateDocAndToken is the equivalent of calling createDoc followed by getClientToken:

const manager = new DocumentManager(CONNECTION_STRING)
const doc = manager.createDoc("myDocId")
const clientToken = manager.getClientToken(doc)

The client token can then be passed to the client application and used there to authenticate with the Y-Sweet server to read / write to the document.

💡

If you don't want a doc to be automatically generated for you, you can just use getClientToken directly.

y-sweet was created by Drifting in Space.