Authentication in the SDK
The publishable key goes in every client. A session token goes beside it for the Data API, for drafts and for every write. Your server mints the token with the secret key, and the app keeps it fresh.
Call postSession with your secret key, for the user your own sign-in names:
Your session route answers session.toJson(); the server quickstart serves it at POST /session.
Give the client a SessionTokenEngine. It calls your route, and mints again before each token expires:
One client serves the whole app. Each request, and each map tile, carries the current token. Call sessions.refresh() after your user signs in, and sessions.disable() when they sign out.
A share link carries a share token, which replaces the key for its visitor:
Credential(publishableKey:, shareToken:) builds the credential from parts you hold apart, and sends the share token alone when both are set.
A token minted without user_id reads only what your organization publishes, and writes nothing. To write, mint the token for the member your own sign-in vouches for:
Read the member's id from your server's own session, never from the request.
SecretCredential exists on the Dart VM only. In a Flutter build the name does not exist, so code that holds a secret key does not compile, and no key can ship inside an app.