Julien ๐Ÿ
Julien ๐Ÿ
BABetter Auth
Created by Julien ๐Ÿ on 5/18/2025 in #help
OAuth with TikTok failing โ€” โ€œcode_challengeโ€ error on redirect
Hi! Iโ€™m integrating BetterAuth in my Next.js app with a custom PostgreSQL schema via Prisma. Everything works fine locally, but when I try to sign in with the TikTok provider on my deployed Vercel app, Iโ€™m redirected to a TikTok error page saying: โ€œAn error occurred. TikTok login failed. This may be due to application-specific settings. If youโ€™re a developer, fix the following and try again: code_challenge.โ€ Iโ€™m not doing any manual PKCE handling in my code, and I assumed BetterAuth manages it internally. Hereโ€™s my current BetterAuth config:
export const auth = betterAuth({
database: prismaAdapter(prisma, { provider: "postgresql" }),
emailAndPassword: { enabled: true },
socialProviders: {
tiktok: {
clientId: process.env.TIKTOK_CLIENT_ID,
clientSecret: process.env.TIKTOK_CLIENT_SECRET,
clientKey: process.env.TIKTOK_CLIENT_KEY,
},
},
});
export const auth = betterAuth({
database: prismaAdapter(prisma, { provider: "postgresql" }),
emailAndPassword: { enabled: true },
socialProviders: {
tiktok: {
clientId: process.env.TIKTOK_CLIENT_ID,
clientSecret: process.env.TIKTOK_CLIENT_SECRET,
clientKey: process.env.TIKTOK_CLIENT_KEY,
},
},
});
Also, my signIn call looks like this:
await signIn.social(
{
provider: "tiktok",
callbackURL: "/dashboard/settings",
},
{
onRequest: () => setLoading(true),
onResponse: () => setLoading(false),
}
);
await signIn.social(
{
provider: "tiktok",
callbackURL: "/dashboard/settings",
},
{
onRequest: () => setLoading(true),
onResponse: () => setLoading(false),
}
);
Is there something Iโ€™m missing regarding PKCE or TikTok support on BetterAuth? Thanks a lot for your help!
7 replies