The surfaces
The three strategies are for the ingestion of events. The Query API key and the MCP token are
separate. A Query API key works with every SDK strategy.
NONE
NONE is the default strategy of Analytics Web. The SDK sends events and reads configurations
with the tenant alias and no credential:
NONE for a public website, a landing page, development, or an app without user login.
SERVER_SIDE
SERVER_SIDE sends a secret key with every request in the Authorization: Chase <secret>
header. The server validates the secret before it processes the request. Use it in a Node.js
backend, a server-side API route, a serverless function, or any other environment that keeps a
secret out of the browser.
To get the secret key:
- Open the dashboard at
https://grainql.com/dashboard. - Open the settings of your tenant.
- Generate or copy the secret key.
- Store it in an environment variable.
JWT
JWT is for a browser app that already has a user login. Before each request, the SDK calls
authProvider.getToken() and sends the result in the Authorization: Bearer <token> header.
getToken returns a string or a Promise<string>.
Configure the JWT in the settings of your tenant in the dashboard:
- The JWT issuer, for example your Auth0 domain.
- The JWT audience.
- The public key or the JWKS endpoint.
authProvider to the SDK:
getToken is getAccessTokenSilently from @auth0/auth0-react. With NextAuth.js,
getToken returns session.accessToken from getSession(). login({ authToken }) also sets
the strategy to JWT at run time. Read Identify users.
The user ID must match the token
WithJWT, the user ID in an event must equal the sub claim of the token. The server rejects
an event with another user ID. This rule stops one user from sending events as another user.
One configuration for two environments
The strategy is a configuration value, so one code path can serve development and production:Query API key
The Query API reads events out of Grain. It needs an API key with the “Query API” permission. The key is separate from the SDK strategies and from the secret key.- Open Dashboard → Settings → Authentication at
https://grainql.com/dashboard/settings. - Click Generate New Secret.
- Enter a name, for example
Query API key. - Select the Query API permission.
- Copy the key and store it in an environment variable.
X-API-Key header:
MCP server
An AI assistant authenticates with OAuth 2.1. The MCP client registers itself, you approve the scopes on a consent screen, and the client receives anmcpat_… access token. No secret is
copied by hand. Read MCP server.