Kakao
Get your Kakao Credentials
To use Kakao sign in, you need a client ID and client secret. 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 social_providers option of the auth instance.
- The default scopes are
account_email,profile_image, andprofile_nickname. - Note that retrieving
account_emailrequires the app to be a Biz App (an app that has completed business verification). For more details, refer to the Kakao Login scopes documentation.
require "better_auth"
auth = BetterAuth.auth(
secret: ENV.fetch("BETTER_AUTH_SECRET"),
base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
social_providers: {
kakao: BetterAuth::SocialProviders.kakao(
client_id: ENV.fetch("KAKAO_CLIENT_ID"),
client_secret: ENV.fetch("KAKAO_CLIENT_SECRET")
)
}
)Sign In with Kakao
To sign in with Kakao, call auth.api.sign_in_social on your Ruby auth instance. The endpoint body takes the following properties:
provider: The provider to use. It should be set tokakao.
response = auth.api.sign_in_social(
body: {
provider: "kakao",
callback_url: "/dashboard",
error_callback_url: "/login",
disable_redirect: true
}
)
redirect_url = response.fetch(:url)