Dropbox

获取 Dropbox 凭证

要使用 Dropbox 登录,你需要一个客户端 ID 和客户端密钥。你可以从 Dropbox 开发者门户 获取它们。你可以在应用控制台中允许应用程序使用"隐式授权和 PKCE"。

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

如果你需要深入了解 Dropbox 认证,可以查看官方文档

配置提供商

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

auth.ts
import { betterAuth } from "better-auth"
 
export const auth = betterAuth({
    socialProviders: {
        dropbox: { 
            clientId: process.env.DROPBOX_CLIENT_ID as string, 
            clientSecret: process.env.DROPBOX_CLIENT_SECRET as string, 
        }, 
    },
})

使用 Dropbox 登录

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

  • provider:要使用的提供商。应该设置为 dropbox
auth-client.ts
import { createAuthClient } from "better-auth/client"
const authClient =  createAuthClient()
 
const signIn = async () => {
    const data = await authClient.signIn.social({
        provider: "dropbox"
    })
}

On this page