> ## Documentation Index
> Fetch the complete documentation index at: https://docs.context.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If the user asks to make Context.dev their default search and scrape provider, follow https://docs.context.dev/default-search-scrape.md. For other setup requests, follow https://docs.context.dev/agent-quickstart.md and start by signing the user up and getting an API key through https://www.context.dev/auth.md. During setup, use the relevant guide already in context instead of fetching it again or loading the full documentation index. Application code reads CONTEXT_DEV_API_KEY.

# Sign in with Context.dev

> Log people in to your product with their Context.dev account, with or without access to the API on their credits.

Add the `profile` scope and the token response tells you who the user is: their account ID, verified email, and name. You can use that to create an account in your product and log them in, the way you would with any other sign-in provider.

The flow is the one in [Connect a user's account](https://docs.context.dev/oauth-apps/connect.md) or, for apps on a device, [CLI, desktop, and mobile apps](https://docs.context.dev/oauth-apps/native-apps.md). Only the scope and what you do with the response change.

## Pick a mode

| You want | `scope` | You get |
| - | - | - |
| Sign-in only | `profile` | The `user` object. The access token cannot call the data APIs or use credits. |
| Sign-in and API access | `profile data:execute`, or other API scopes | The `user` object, and an access token for those scopes. |
| API access only | Scopes without `profile` | No `user` object. See [Connect a user's account](https://docs.context.dev/oauth-apps/connect.md). |

## Sign-in only

Request `profile` alone. The consent screen says your product receives the user's name, verified email, and account ID, and that it cannot use their credits.

The token response carries the `user` object.

```json theme={null}
{
  "access_token": "ctxt_oat_...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "profile",
  "refresh_token": "ctxt_ort_...",
  "organization_id": "...",
  "user": {
    "id": "...",
    "email": "ada@example.com",
    "email_verified": true,
    "name": "Ada Lovelace"
  }
}
```

In your callback, after the code exchange, find or create your user and start a new session.

```javascript theme={null}
const tokens = await response.json();
if (!tokens.user) return res.redirect("/login?error=context");

const account = await findOrCreateUser({
  contextUserId: tokens.user.id,
  email: tokens.user.email,
  name: tokens.user.name,
});
req.session.regenerate((error) => {
  if (error) return next(error);
  req.session.userId = account.id;
  res.redirect("/app");
});
```

* **Start a new session at login.** `req.session.regenerate` replaces the session the visitor had before they signed in, so a session ID planted earlier is useless.
* **Key your user on `user.id`.** It stays the same if the person changes their email.
* **`email` is always verified.** `name` is omitted when the account has none.
* **`organization_id` is the workspace the person picked.** Use it if your product groups people by team.
* **You don't have to keep the tokens.** For sign-in only, read `user` and discard them. Your own session keeps the person logged in.

Signing in again reuses the person's existing sign-in connection to your app. It does not create a new one each time. The person sees the consent screen on every sign-in.

## Sign in and use the API

Request `profile` together with the API scopes you need, for example `profile data:execute`. The consent screen lists both, and names the workspace that pays.

Handle the response in two parts:

1. Log the person in with `user`, as above.
2. Store the tokens and call the API with them, as in [Connect a user's account](https://docs.context.dev/oauth-apps/connect.md#3-call-the-api). Each refresh response includes `user` again.

## Sign in first, connect later

You can ask for `profile` at login and for API access only when a person first uses a feature that needs it. Send them through the flow again with the API scope, such as `data:execute`, and store the tokens from that second flow for API calls.

The two approvals are separate connections. A token can do exactly what its own consent screen listed, so the sign-in token never gains API access, and a later sign-in that asks only for `profile` does not affect the API connection. The user sees both on their Connected apps page and can disconnect either one.

## Sign out and disconnect

These are different actions.

| Action | What to do | Effect |
| - | - | - |
| The person signs out of your product | End your own session. | Nothing changes at Context.dev. Their connection stays, and they approve the consent screen again the next time they sign in. |
| The person disconnects Context.dev from your product | [Revoke the token](https://docs.context.dev/oauth-apps/connect.md#6-disconnect) and delete your copy. | That connection ends and leaves the person's Connected apps page. If you hold a separate API connection, revoke its token too. |

If a person changes the email on their Context.dev account, stored refresh tokens stop working until they sign in again. Their `user.id` is unchanged, so they land in the same account in your product, and `user.email` is their new address.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.