List available authentication providers
Sign-in UI
Auth.js · Function
getProviders() asynchronously retrieves the configured authentication providers in a client-safe record. It can resolve to null when no provider data is available.
Call getProviders without arguments to asynchronously obtain the configured authentication providers in a client-safe form. The result is either null or a record keyed by provider identifiers, so callers commonly guard against null and iterate over the record values.
function getProviders(): Promise<null | Record<ProviderId, ClientSafeProvider>>Promise<null | Record<ProviderId, ClientSafeProvider>>
import { getProviders } from "next-auth/react"
export default async function SignIn() {
const providers = await getProviders()
if (!providers) return <p>No providers configured.</p>
return (
<div>
{Object.values(providers).map((provider) => (
<p key={provider.id}>{provider.name}</p>
))}
</div>
)
}Fetches the configured, client-safe providers and renders each provider name.
Sign-in UI
Provider discovery
Next.js routing
getProviders returns a promise resolving to either null or a record of client-safe providers. Each record key is a provider identifier, and the values contain the data suitable for presenting sign-in choices.
Follow-up: How should the result be rendered? Guard against null, then iterate over Object.values of the record and use each provider's id as a stable key.
It takes no parameters: the function signature is getProviders(). The returned promise resolves to the configured providers rather than requiring provider configuration as an argument.
Follow-up: What type describes the provider entries? ClientSafeProvider describes the values, while ProviderId describes the record keys.
The function is part of the Next.js React integration and is used to obtain a client-safe list of configured providers for a sign-in interface. It supports both Client Components and the Pages Router.
Follow-up: Where would provider configuration come from? It is configured in the Auth.js setup and exposed to this helper as the available provider list.
ClientSafeProviderProviderIdsignInNextAuth.js