Advanced
getOrCreateDoc

getOrCreateDoc

getOrCreateDoc is a helper from our Javascript SDK (opens in a new tab) that checks for a docId and generates a client token that can be used to connect to the document associated to its given ID.

Looking through the code (opens in a new tab) can be instructive for understanding how exactly getOrCreateDoc works.

If a doc is undefined, getOrCreateDocwill automatically generate a doc and associated docID for you. This is the docId that shows up as a search param in your app url.

And if you're using y-sweet for authentication, getOrCreateDoc will provide an authorization token.

💡

Say that you don't want a doc to be automatically generated for you, you can directly use getClientToken (opens in a new tab), which is what getOrCreateDoc calls to generate the client token.

y-sweet was created by Drifting in Space.