reactive/data-client / .agents/skills/data-client-setup
data-client-setup
VerifiedInstall and set up @data-client/react or @data-client/vue in a project. Detects project type (NextJS, Expo, React Native, Vue, plain React) and protocol (REST, GraphQL, custom), then follows the bundled protocol-specific setup guide.
references/data-client-graphql-setup/references/auth.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/graphql/auth.md (react). Edit the source doc, not this file. -->
# GraphQL Authentication
## Cookie Auth
Here's an example using simple cookie auth:
```ts title="schema/endpoint.ts"
import { GQLEndpoint } from '@data-client/graphql';
class CookieGQLEndpoint extends GQLEndpoint<any> {
getRequestInit(variables: any): RequestInit {
return {
...super.getRequestInit(variables),
credentials: 'same-origin',
};
}
}
export const gql = new CookieGQLEndpoint(
'https://nosy-baritone.glitch.me',
);
export default gql;
```
## Access Tokens
Here we'll keep the access token in a module variable and send it in a header. Endpoints made with
`gql.query()` and `gql.mutation()` copy `gql` when they are created, so a value set on `gql` afterward
would not reach them; a module variable is read on every request.
```ts title="schema/endpoint.ts"
import { GQLEndpoint } from '@data-client/graphql';
let accessToken = '';
export function setAccessToken(token: string) {
accessToken = token;
}
export const gql = new GQLEndpoint('https://nosy-baritone.glitch.me', {
getHeaders(headers: HeadersInit): HeadersInit {
return {
...headers,
'Access-Token': accessToken,
};
},
});
export default gql;
```
Then be sure to set the access token upon login:
```ts
import { setAccessToken } from 'schema/endpoint';
function Auth() {
const handleLogin = useCallback(
async e => {
const { accessToken } = await login(new FormData(e.target));
// success!
setAccessToken(accessToken);
},
[login],
);
return <AuthForm onSubmit={handleLogin} />;
}
```
## 401 Logout Handling
In case a users authorization expires, the server will typically responsd to indicate
as such. The standard way of doing this is with a 401. [LogoutManager](https://dataclient.io/docs/api/LogoutManager)
can be used to easily trigger any de-authorization cleanup.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |