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!
6 Replies
iPheNoMeNaL-oG
iPheNoMeNaL-oG4mo ago
@Julien 🍁 You figure this out? Running into this now as well
Julien 🍁
Julien 🍁OP4mo ago
no 😞
iPheNoMeNaL-oG
iPheNoMeNaL-oG4mo ago
@Julien 🍁 I cannot seem to find a solution or even really what the issue is woah I got it to work
Oli
Oli4mo ago
@iPheNoMeNaL-oG care to give any insight on how you fixed this? Also running into the same issue. 🙏 Nvm bad https config for localhost was the issue.
aseppp
aseppp2mo ago
hey, i would like to know what you're doing to fix this error, can you explain?
Oli
Oli2mo ago
@aseppp main problem is that tiktok wants your requests to come from a https url. So one way to solve this is to run ngrok or similar, and instead go to your site via that url, making sure that is set in the tiktok developer settings too.

Did you find this page helpful?