Kakao
Kakao provider setup and usage.
Get your Kakao Credentials
To use Kakao sign in, you need a Kakao REST API key and client secret. Use the REST API key as the clientId. Kakao enables the client secret by default, so clientSecret must be configured. You can get them from the Kakao Developer Portal.
Make sure to set the redirect URL to http://localhost:3000/api/auth/callback/kakao for local development. For production, you should set it to the URL of your application. If you change the base path of the auth routes, you should update the redirect URL accordingly.
Configure the provider
To configure the provider, you need to import the provider and pass it to the socialProviders option of the auth instance.
import { betterAuth } from "better-auth"
export const auth = betterAuth({
socialProviders: {
kakao: {
clientId: process.env.KAKAO_CLIENT_ID as string,
clientSecret: process.env.KAKAO_CLIENT_SECRET as string,
},
}
})Sign In with Kakao
To sign in with Kakao, you can use the signIn.social function provided by the client.
import { createAuthClient } from "better-auth/client"
const authClient = createAuthClient()
const signIn = async () => {
const data = await authClient.signIn.social({
provider: "kakao"
})
}Usage
Sign In with Kakao using ID Token
If your app signs in with Kakao's native SDKs (Android, iOS, or Flutter), you can pass the ID token to signIn.social to sign in without redirection.
- Enable OpenID Connect in the Kakao Developers console.
- ID tokens from the SDKs are issued for the app key used to initialize the SDK, so add your native app key to
clientId. Keep the REST API key first, since the redirect flow uses the first key.
import { betterAuth } from "better-auth"
export const auth = betterAuth({
socialProviders: {
kakao: {
clientId: [
process.env.KAKAO_REST_API_KEY as string,
process.env.KAKAO_NATIVE_APP_KEY as string,
],
clientSecret: process.env.KAKAO_CLIENT_SECRET as string,
},
}
})const data = await authClient.signIn.social({
provider: "kakao",
idToken: {
token: kakaoIdToken, // ID token from the Kakao SDK
},
})The user is created from the ID token claims (sub, nickname, picture, and email). The ID token has no email verification status, so emailVerified is false, and an existing user with the same email is linked only when Kakao is one of the trusted providers.
Options
Scopes
The default scopes are account_email, profile_image, and profile_nickname. Retrieving account_email is available for Biz Apps and test apps. For more details, refer to the Kakao Login utilization documentation.
If OpenID Connect is enabled for your app, add openid to scope to receive an ID token in the redirect flow as well.
If your app can't configure account_email, set disableDefaultScope to true and list the scopes you still need under scope.
import { betterAuth } from "better-auth"
export const auth = betterAuth({
socialProviders: {
kakao: {
clientId: process.env.KAKAO_CLIENT_ID as string,
clientSecret: process.env.KAKAO_CLIENT_SECRET as string,
disableDefaultScope: true,
scope: ["profile_image", "profile_nickname"],
},
}
})Troubleshooting
KOE205 error
Kakao returns KOE205 when the authorization request includes a scope that isn't enabled for your app. Enable the scope in the Kakao Developers console, or change the requested scopes as shown in Scopes.
email_not_found error
Kakao returns no email when account_email isn't requested or the user doesn't grant it. Sign-in with an ID token fails with USER_EMAIL_NOT_FOUND for the same reason. Add a fallback with mapProfileToUser as shown in Handling Providers Without Email.