Add WordPress login to Next.js
Users sign in to a Next.js application with WordPress.com accounts.
Auth.js · Const
Auth.js provides a built-in WordPress OAuth provider. Register its callback URL, supply the WordPress client credentials, and add WordPress to the Auth.js providers configuration.
The WordPress provider is a built-in OAuth integration. Add the provider to Auth.js configuration, set the WordPress client credentials through AUTH_WORDPRESS_ID and AUTH_WORDPRESS_SECRET, and register the callback URL at /api/auth/callback/wordpress.
function default(config): OAuthConfig<Record<string, any>>| Name | Type | Description |
|---|---|---|
config | OAuthUserConfig<Record<string, any>> | Optional OAuth provider configuration, including client credentials or overrides for the built-in settings. |
OAuthConfig<Record<string, any>>
import NextAuth from "next-auth"
import WordPress from "next-auth/providers/wordpress"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [WordPress],
})Registers the built-in WordPress provider with NextAuth; credentials are read from the documented environment variables.
Users sign in to a Next.js application with WordPress.com accounts.
A core Auth.js integration needs a provider definition with explicit client credentials.
A WordPress OAuth deployment differs from the built-in assumptions.
The provider can be added directly as WordPress in a framework configuration, or called as WordPress({ clientId, clientSecret }) in the core API. Auth.js uses the provider's built-in defaults unless you override them.
Follow-up: How would you customize it? Pass provider options to the function and merge them with the built-in defaults, changing only the settings required by the WordPress installation.
For a Next.js setup, import WordPress from next-auth/providers/wordpress and include it in the providers array passed to NextAuth. The documented environment variables are AUTH_WORDPRESS_ID and AUTH_WORDPRESS_SECRET.
Follow-up: What must be configured outside the application? The WordPress client must be registered with the callback URL https://example.com/api/auth/callback/wordpress.
The core provider factory accepts an OAuthUserConfig<Record<string, any>> configuration object and returns an OAuthConfig<Record<string, any>>. The configuration can provide client credentials and overrides for the default OAuth setup.
Follow-up: Why is the return type useful? It supplies the normalized provider definition that Auth.js consumes in its providers configuration.
OAuthConfigOAuthUserConfigcustomizing a built-in OAuth providerNextAuthWordPress