The `better-auth-instagram` package provides an Instagram OAuth provider specifically designed to integrate with the `better-auth` authentication framework. Currently at version 0.0.7, it functions as a plugin, allowing developers to easily add 'Login with Instagram' functionality to their TypeScript applications. It leverages `@better-fetch/fetch` for making robust API requests and `zod` for schema validation, aligning with the `better-auth` ecosystem's focus on type-safety and developer experience. While `better-auth` (currently at 1.4.0) offers a comprehensive, framework-agnostic authentication solution with a plugin-based architecture, `better-auth-instagram` simplifies the complexities of Instagram's OAuth flow, requiring proper setup of an Instagram Business Login API application. Its release cadence is tied to the `better-auth` ecosystem, focusing on incremental improvements and compatibility. Key differentiators include its tight integration with `better-auth`'s plugin system and built-in type safety with Zod.
npm install better-auth-instagramVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic server-side setup of `better-auth` with the `better-auth-instagram` plugin and how to initiate the client-side OAuth flow.
Review and update your Instagram Developer App settings to ensure it's configured for 'Instagram Business Login' and not 'Basic Display'. Verify required permissions/scopes are enabled and the authorized redirect URI matches your application's callback URL (e.g., `http://localhost:3000/api/auth/oauth2/callback/instagram`).
Carefully review release notes for any updates. Pin exact versions in your `package.json` to prevent unexpected behavior with `better-auth-instagram` and its peer dependencies. Consider contributing to help stabilize the API.
Follow the Instagram Developer documentation for setting up an Instagram app for 'Instagram Business Login'. Ensure the app is in 'Live Mode' or that all users attempting to log in are added as 'Testers' and have accepted the invitation.
Implement database hooks or custom logic within your `betterAuth` configuration to fetch and update user profile data from the Instagram API after a successful authentication event. The package provides utility functions for Instagram API interaction for this purpose.
Ensure that `INSTAGRAM_APP_ID` and `INSTAGRAM_APP_SECRET` are correctly configured in your server's environment variables (e.g., `.env` file) and are accessible to your `better-auth` instance. Confirm they match the credentials from your Instagram Developer App.
Ensure that the callback handler processes the authorization code promptly and only once. Check server logs for any repeated attempts or slow responses during the code exchange phase. Verify server time synchronization.
Go to your Instagram Developer App settings. Under 'Instagram Basic Display' or 'Instagram Business Login' (depending on your setup), navigate to 'Client OAuth Settings' and ensure the `http://localhost:3000/api/auth/oauth2/callback/instagram` (or your production URL) is added and exactly matches the URI used in your `better-auth` configuration.
This is expected user behavior. Handle this gracefully in your client-side application, perhaps by redirecting them back to a login page or displaying a message indicating that Instagram login was canceled.
Inspect the detailed error message for the specific field that failed validation. This might indicate an unexpected API response format from Instagram or a mismatch in your `instagramConfig` or data processing logic. If it's an upstream API change, an update to `better-auth-instagram` might be needed.