isProviderConnected
Complete API reference for the api.isProviderConnected method, verifying whether the current session has an active connection with a specific OAuth provider.
The api.isProviderConnected method checks whether the current session has an active connection with a specific OAuth provider. This method runs on the server, so it requires you to pass the request or headers object from your server-side context.
import { api } from "@/lib/auth"
const output = await api.isProviderConnected("github", {
request: getRequest(),
})This method only checks connection status — it doesn't return any token data. If you need the access token itself, use
api.getAccessToken instead.
Reference
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| providerId | string | Yes | The id of the OAuth provider to check the connection for. |
| options | ProviderConnectedAPIOptions | Yes | An object containing request context. |
ProviderConnectedAPIOptions
| Option | Type | Default | Description |
|---|---|---|---|
| request | Request | undefined | The request object from the server-side context. |
| headers | Headers | undefined | The headers object from the server-side context. |
| skipCSRFCheck | boolean | false | Whether to skip CSRF token verification for this request. |
At least one of request or headers is required to construct the incoming URL and validate redirect URLs.
Returns
| Return Type | Description |
|---|---|
Promise<ProviderConnectedAPIReturn> | Resolves to an object containing success and connected — see Behavior. |
Behavior
- On success,
connectedresolves totrueorfalsedepending on whether the specified provider is currently connected to the session — it does not throw for the "not connected" case, since that's an expected outcome, not an error. - CSRF protection is verified by default. Set
skipCSRFCheck: trueonly if you're enforcing CSRF protection at a different layer (e.g. a framework-level middleware) — disabling it here without an equivalent safeguard reintroduces the vulnerability it protects against. - If the check itself fails (e.g. no valid session),
connectedresolves tonullandsuccessisfalse— distinct fromconnected: false, which means the check succeeded and simply found no connection.
Usage
Check a provider's connection status
import { api } from "@/lib/auth"
const { success, connected } = await api.isProviderConnected("github", {
request: getRequest(),
})Prompting the user to connect a provider
import { api } from "@/lib/auth"
const { success, connected } = await api.isProviderConnected("github", {
request: getRequest(),
})
if (success && !connected) {
redirect("/settings/connections/github")
}