@tenshowinnovation/better-auth-cn-plugins
v0.1.0
Published
Better Auth OAuth provider helpers for WeChat and Douyin.
Maintainers
Readme
@tenshowinnovation/better-auth-cn-plugins
Better Auth OAuth provider helpers for WeChat and Douyin.
Install
pnpm add @tenshowinnovation/better-auth-cn-pluginsThis package expects better-auth >=1.6.0 <2 to be installed by your app.
Usage
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";
import { douyin, wechat } from "@tenshowinnovation/better-auth-cn-plugins";
export const auth = betterAuth({
plugins: [
genericOAuth({
config: [
wechat({
clientId: process.env.WECHAT_CLIENT_KEY!,
clientSecret: process.env.WECHAT_CLIENT_SECRET!,
}),
douyin({
clientId: process.env.DOUYIN_CLIENT_KEY!,
clientSecret: process.env.DOUYIN_CLIENT_SECRET!,
}),
],
}),
],
});Better Auth's generic OAuth callback path is:
/api/auth/oauth2/callback/{providerId}For the default providers, configure these callback paths in the WeChat and Douyin developer consoles:
/api/auth/oauth2/callback/wechat
/api/auth/oauth2/callback/douyinProvider Notes
- WeChat
clientIdis the WeChat appid, andclientSecretis the app secret. - Douyin
clientIdis the Douyinclient_key, andclientSecretisclient_secret. - WeChat defaults to the
snsapi_loginscope. - Douyin defaults to the
user_infoscope. - Both providers generate a fallback email because neither provider reliably returns one.
Fallback Emails
By default, fallback emails use ${accountId}@tempemail.com.
wechat({
clientId: process.env.WECHAT_CLIENT_KEY!,
clientSecret: process.env.WECHAT_CLIENT_SECRET!,
emailDomain: "example.local",
});You can fully override the generated email:
douyin({
clientId: process.env.DOUYIN_CLIENT_KEY!,
clientSecret: process.env.DOUYIN_CLIENT_SECRET!,
getEmail: (accountId, providerId) => `${providerId}-${accountId}@example.local`,
});Subpath Imports
import { wechat } from "@tenshowinnovation/better-auth-cn-plugins/wechat";
import { douyin } from "@tenshowinnovation/better-auth-cn-plugins/douyin";