Better-Auth
Better-Auth Integration
Section titled “Better-Auth Integration”MC-ID is built using better-auth and is fully compatible with it. This guide shows how to add MC-ID as an identity provider in your better-auth application.
Installation
Section titled “Installation”npm install better-authConfiguration
Section titled “Configuration”Use the genericOAuth plugin to add MC-ID as a provider:
import { betterAuth } from "better-auth";import { genericOAuth } from "better-auth/plugins";
export const auth = betterAuth({// ... your other configplugins: [ genericOAuth({ config: [ { providerId: "mc-id", clientId: process.env.MCID_CLIENT_ID!, clientSecret: process.env.MCID_CLIENT_SECRET!, discoveryUrl: "https://mc-id.com/.well-known/openid-configuration", scopes: ["openid", "profile", "email", "connections"], } ] })]});Available Scopes
Section titled “Available Scopes”See MC-ID Scopes
Client-Side Usage
Section titled “Client-Side Usage”Once configured, you can trigger the MC-ID login flow:
import { signIn } from "./auth-client";
// Redirect to MC-ID loginsignIn("mc-id", { callbackURL: "/dashboard" });User Data
Section titled “User Data”After authentication, the user object will include the claims from the userinfo endpoint based on the scopes you requested:
{ "sub": "AaltJ3XUoyDQiqDVk865CILljZBXrjZz", "name": "Notch", "email": "user@example.com", "email_verified": true, "accounts": [ { "uuid": "069a79f444e94726a5befca90e38aaf5", "primary": true, "username": "Notch" } ], "connections": [ { "providerId": "discord", "accountId": "123456789012345678" } ]}