Naver
获取你的 Naver 凭证
要使用 Naver 登录,你需要一个客户端 ID 和客户端密钥。你可以从 Naver 开发者 获取它们。
请确保将重定向 URL 设置为 http://localhost:3000/api/auth/callback/naver 以进行本地开发。对于生产环境,你应将其设置为你应用的 URL。如果你更改了身份验证路由的基础路径,则应相应地更新重定向 URL。
配置提供者
要配置提供者,你需要导入该提供者并将其传递给 auth 实例的 socialProviders 选项。
import { betterAuth } from "better-auth"
export const auth = betterAuth({
socialProviders: {
naver: {
clientId: process.env.NAVER_CLIENT_ID as string,
clientSecret: process.env.NAVER_CLIENT_SECRET as string,
},
}
})Sign In with Naver
To sign in with Naver, you can use the signIn.social function provided by the client. The signIn function takes an object with the following properties:
provider: The provider to use. It should be set tonaver.
import { createAuthClient } from "better-auth/client"
const authClient = createAuthClient()
const signIn = async () => {
const data = await authClient.signIn.social({
provider: "naver"
})
}