Hugging Face

Hugging Face 提供者的设置与使用。

获取 Hugging Face 凭证

要使用 Hugging Face 登录,您需要客户端 ID 和客户端密钥。Hugging Face OAuth 文档。请确保在 Hugging Face 上创建的 OAuth 应用程序具有 "email" 作用域。

请确保将重定向 URL 设置为 http://localhost:3000/api/auth/callback/huggingface,用于本地开发。对于生产环境,应将其设置为应用程序的 URL。如果更改了认证路由的基本路径,请相应地更新重定向 URL。

配置提供者

要配置提供者,您需要导入提供者并将其传递给 auth 实例的 socialProviders 选项。

auth.ts
import { betterAuth } from "better-auth"

export const auth = betterAuth({
    socialProviders: {
        huggingface: { 
            clientId: process.env.HUGGINGFACE_CLIENT_ID as string, 
            clientSecret: process.env.HUGGINGFACE_CLIENT_SECRET as string, 
        }, 
    },
})

使用 Hugging Face 登录

要使用 Hugging Face 登录,您可以使用客户端提供的 signIn.social 函数。signIn 函数接收一个包含以下属性的对象:

  • provider:要使用的提供者。应设置为 huggingface。
auth-client.ts
import { createAuthClient } from "better-auth/client"
const authClient =  createAuthClient()

const signIn = async () => {
    const data = await authClient.signIn.social({
        provider: "huggingface"
    })
}