Polar
获取你的 Polar 凭据
要使用 Polar 登录,你需要创建一个 OAuth 2.0 客户端。你可以从 Polar 用户设置 获取你的凭据。
- 前往你的 Polar 用户设置
- 点击“创建 OAuth 客户端”
- 填写必填字段:
- 应用名称:在授权过程中向用户显示的名称
- 客户端类型:为你的应用选择适当的客户端类型
- 重定向 URI:在本地开发时设置为
http://localhost:3000/api/auth/callback/polar。在生产环境中,设置为https://yourdomain.com/api/auth/callback/polar。如果更改了认证路由的基础路径,请相应更新重定向 URI。 - 权限范围:选择你的应用所需的权限(openid、profile、email 为默认权限)
- 首页网址:你应用的主网址
- 可选择地,添加:
- 你的应用的徽标
- 服务条款网址
- 隐私政策网址
- 创建后,将客户端ID和客户端密钥复制到你的环境变量中。请保持这些凭据的安全。
配置提供程序
要配置提供程序,你需要导入该提供程序并将其传递给身份验证实例的 socialProviders 选项。
import { betterAuth } from "better-auth"
export const auth = betterAuth({
socialProviders: {
polar: {
clientId: process.env.POLAR_CLIENT_ID as string,
clientSecret: process.env.POLAR_CLIENT_SECRET as string,
},
},
})Sign In with Polar
To sign in with Polar, you can use the signIn.social function provided by the client, where the provider should be set to polar.
import { createAuthClient } from "better-auth/client"
const authClient = createAuthClient()
const signIn = async () => {
const data = await authClient.signIn.social({
provider: "polar"
})
}