Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Const

spotify

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.

How it works

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.

Syntax

betterAuth({ socialProviders: { spotify: { clientId, clientSecret } } })
authClient.signIn.social({ provider: "spotify" })

Parameters

NameTypeDescription
providerstringThe social provider identifier; for this integration it must be spotify.

Returns

The page does not specify a return shape for the Spotify sign-in call.

Key points

  • Spotify setup requires both OAuth credentials: a client ID and a client secret.
  • Create or retrieve the required credentials in Spotify’s Developer Portal.
  • Register the provider in the socialProviders option of the Better Auth instance.
  • The client sign-in method receives its options in an object.
  • Set the sign-in options’ provider field to spotify.

Common mistakes

  • Use 127.0.0.1 rather than localhost for local redirect configuration.
  • The browser’s local application URL must use the same loopback host as the configured redirect URI.

Example: Configure Spotify sign-in

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.

When to use it

Spotify social sign-in

Add Spotify as an OAuth login option in a Better Auth application.

Local development

Run the OAuth callback locally using Spotify’s supported loopback redirect host.

Environment-based credentials

Keep Spotify OAuth credentials outside source code while configuring the provider.

Interview questions

QHow do you configure Spotify sign-in in Better Auth?

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.

QWhat provider value does the sign-in call use?

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.

QWhich credentials are required for the Spotify provider?

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.

  • socialProviders
  • signIn.social
  • createAuthClient
  • clientId
  • clientSecret
  • BETTER_AUTH_URL

Source: authenticationSpotify | Better Auth. Checked 2026-10-15.