Spotify social sign-in
Add Spotify as an OAuth login option in a Better Auth application.
Better Auth · Const
Better Auth’s Spotify provider enables OAuth sign-in by configuring Spotify client credentials under socialProviders.spotify, then calling signIn.social with provider: "spotify". Local development must use 127.0.0.1 instead of localhost for the redirect URI.
The Spotify integration registers credentials under the spotify key in Better Auth’s socialProviders configuration. The client then calls signIn.social with provider: "spotify" to begin OAuth authentication; local development must use the documented loopback address so the redirect URI matches exactly.
betterAuth({ socialProviders: { spotify: { clientId, clientSecret } } })
authClient.signIn.social({ provider: "spotify" })| Name | Type | Description |
|---|---|---|
provider | string | The social provider identifier; for this integration it must be spotify. |
The page does not specify a return shape for the Spotify sign-in call.
socialProviders option of the Better Auth instance.provider field to spotify.127.0.0.1 rather than localhost for local redirect configuration.import { betterAuth } from "better-auth";
import { createAuthClient } from "better-auth/client";
export const auth = betterAuth({
socialProviders: {
spotify: {
clientId: process.env.SPOTIFY_CLIENT_ID!,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET!,
},
},
});
const authClient = createAuthClient();
await authClient.signIn.social({ provider: "spotify" });Configure Spotify with its OAuth credentials, then start sign-in through the client’s social authentication method.
Add Spotify as an OAuth login option in a Better Auth application.
Run the OAuth callback locally using Spotify’s supported loopback redirect host.
Keep Spotify OAuth credentials outside source code while configuring the provider.
Register Spotify in socialProviders and provide its clientId and clientSecret. The client starts authentication with authClient.signIn.social({ provider: "spotify" }).
Follow-up: What local redirect-host issue can prevent the flow from working? Spotify requires 127.0.0.1, not localhost, and the application URL must match that host.
The provider identifier is the literal string spotify. It is used both as the configuration key under socialProviders and as the provider value passed to signIn.social.
Follow-up: What must be consistent beyond the provider identifier? The Spotify dashboard redirect URI, Better Auth URL, and browser URL must match the documented loopback address.
Spotify authentication requires a client ID and client secret obtained from the Spotify Developer Portal. These values are supplied in the provider configuration, typically from environment variables.
Follow-up: What redirect requirement accompanies those credentials during local development? Configure the callback with 127.0.0.1:3000 and use that address in the browser.
socialProviderssignIn.socialcreateAuthClientclientIdclientSecretBETTER_AUTH_URL