[GH-ISSUE #3258] TikTok login flow returns 200 but does not redirect or show TikTok login prompt (signIn.social) #9543

Closed
opened 2026-04-13 05:02:35 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Vi-obb on GitHub (Jul 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3258

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up better-auth in a Next.js App Router project using signIn.social({ provider: "tiktok" }).

  2. Create a sandbox env in tiktok developer portal with callback uri: https://NGROK_url/api/auth/callback/tiktok

  3. Create auth-client.ts and use in sign in button

import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient({
  baseURL: process.env.BETTER_AUTH_URL,
});

export const signInWithTikTok = async () => {
  const data = await authClient.signIn.social({
    provider: "tiktok",
    callbackURL: "/dashboard",
    errorCallbackURL: "/sign-in/error",
    newUserCallbackURL: "/onboarding",
  });
};
  1. When button is clicked, TikTok Login URL is never opened, no pop-up or redirect happens.

  2. The client receives a 200 response from POST /api/auth/sign-in/social.

Current vs. Expected behavior

Current Behavior:

•	signIn.social() triggers a POST /api/auth/sign-in/social that returns 200.
•	The browser does not open TikTok’s OAuth prompt.
•	The signIn call completes, but no redirect happens, and data.url is undefined.
•	TikTok is never shown to the user.

Expected Behavior:

•	Browser should redirect the user to TikTok’s OAuth consent screen.
•	The login flow should behave like other providers (e.g., Google).

What version of Better Auth are you using?

^1.2.12

Provide environment information

- OS: macOS Sequoia 15.5
- Browser: Google Chrome
- Nextjs app router 15.3.4
- Public redirect domain via Ngrok

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/drizzle";
import { nextCookies } from "better-auth/next-js";
import { schema } from "@/drizzle/schema";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema,
  }),
  socialProviders: {
    tiktok: {
      clientId: process.env.TIKTOK_CLIENT_ID as string,
      clientSecret: process.env.TIKTOK_CLIENT_SECRET as string,
      clientKey: process.env.TIKTOK_CLIENT_KEY as string,
    },
  },
  plugins: [nextCookies()],
});

Additional context

No response

Originally created by @Vi-obb on GitHub (Jul 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3258 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Set up better-auth in a Next.js App Router project using signIn.social({ provider: "tiktok" }). 2. Create a sandbox env in tiktok developer portal with callback uri: `https://NGROK_url/api/auth/callback/tiktok` 3. Create auth-client.ts and use in sign in button ``` import { createAuthClient } from "better-auth/client"; const authClient = createAuthClient({ baseURL: process.env.BETTER_AUTH_URL, }); export const signInWithTikTok = async () => { const data = await authClient.signIn.social({ provider: "tiktok", callbackURL: "/dashboard", errorCallbackURL: "/sign-in/error", newUserCallbackURL: "/onboarding", }); }; ``` 4. When button is clicked, TikTok Login URL is never opened, no pop-up or redirect happens. 5. The client receives a 200 response from POST /api/auth/sign-in/social. ### Current vs. Expected behavior #### Current Behavior: • signIn.social() triggers a POST /api/auth/sign-in/social that returns 200. • The browser does not open TikTok’s OAuth prompt. • The signIn call completes, but no redirect happens, and data.url is undefined. • TikTok is never shown to the user. #### Expected Behavior: • Browser should redirect the user to TikTok’s OAuth consent screen. • The login flow should behave like other providers (e.g., Google). ### What version of Better Auth are you using? ^1.2.12 ### Provide environment information ```bash - OS: macOS Sequoia 15.5 - Browser: Google Chrome - Nextjs app router 15.3.4 - Public redirect domain via Ngrok ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/drizzle"; import { nextCookies } from "better-auth/next-js"; import { schema } from "@/drizzle/schema"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema, }), socialProviders: { tiktok: { clientId: process.env.TIKTOK_CLIENT_ID as string, clientSecret: process.env.TIKTOK_CLIENT_SECRET as string, clientKey: process.env.TIKTOK_CLIENT_KEY as string, }, }, plugins: [nextCookies()], }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 05:02:35 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 4, 2025):

Hi @Vi-obb! I'm Dosu and I’m helping the better-auth team.

This usually happens if one or more TikTok environment variables (clientId, clientSecret, clientKey) are missing or not loaded correctly. The TikTok provider in Better Auth doesn't validate these before building the authorization URL, so if they're undefined, you'll get a 200 response but no redirect URL—causing the login flow to silently fail without showing the TikTok prompt (source).

Double-check that all TikTok env vars are set and available in both your Next.js and Better Auth server environments. You can also log the response from signIn.social—if data.url is undefined, that's a strong sign of a config issue.

For better error handling, consider adding a check in your frontend to display a message if data.url is missing. Also, make sure your button handler uses e.preventDefault() to avoid event propagation issues that can block redirects (example).

Unlike Google and some other providers, TikTok doesn't throw a config error, so this kind of silent failure is possible. Improving config validation for TikTok would help avoid this in the future.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3034150332 --> @dosubot[bot] commented on GitHub (Jul 4, 2025): <!-- Greeting --> Hi @Vi-obb! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This usually happens if one or more TikTok environment variables (clientId, clientSecret, clientKey) are missing or not loaded correctly. The TikTok provider in Better Auth doesn't validate these before building the authorization URL, so if they're undefined, you'll get a 200 response but no redirect URL—causing the login flow to silently fail without showing the TikTok prompt [(source)](https://github.com/better-auth/better-auth/blob/93a5a84851c338c2bd238b515e965aae0df18f88/packages/better-auth/src/social-providers/tiktok.ts). Double-check that all TikTok env vars are set and available in both your Next.js and Better Auth server environments. You can also log the response from `signIn.social`—if `data.url` is undefined, that's a strong sign of a config issue. For better error handling, consider adding a check in your frontend to display a message if `data.url` is missing. Also, make sure your button handler uses `e.preventDefault()` to avoid event propagation issues that can block redirects [(example)](https://github.com/better-auth/better-auth/issues/2843). Unlike Google and some other providers, TikTok doesn't throw a config error, so this kind of silent failure is possible. Improving config validation for TikTok would help avoid this in the future. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/0d3fde80-b425-4f77-8d76-b09fadbdfd07?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3258)
Author
Owner

@Vi-obb commented on GitHub (Jul 4, 2025):

@dosu Thanks. The OAuth prompt shows now. However, when I try to sign in, I get this error:

Image
<!-- gh-comment-id:3034166841 --> @Vi-obb commented on GitHub (Jul 4, 2025): @dosu Thanks. The OAuth prompt shows now. However, when I try to sign in, I get this error: <img width="1134" alt="Image" src="https://github.com/user-attachments/assets/e9a5ea65-a7e1-40ba-8108-dc063e15079c" />
Author
Owner

@dosubot[bot] commented on GitHub (Jul 4, 2025):

The "incorrect client_key" error from TikTok means the client_key your app is sending doesn't match what's configured in your TikTok developer portal. This usually happens if the value in your environment variable (TIKTOK_CLIENT_KEY) is missing, has a typo, or doesn't match the one shown in the TikTok dashboard. Double-check that your clientKey, clientSecret, and callback URL in both your Better Auth config and TikTok portal are exactly the same (including case, no extra spaces, and correct app mode—sandbox vs. live). Also, make sure your callback URL matches TikTok's settings exactly, including protocol and path. Better Auth doesn't validate these values, so any mismatch will only show up as an error from TikTok during login, not earlier in the flow (source). If everything looks correct and you still see the error, try regenerating your TikTok credentials and updating your environment variables.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3034168638 --> @dosubot[bot] commented on GitHub (Jul 4, 2025): <!-- Answer --> The "incorrect client_key" error from TikTok means the client_key your app is sending doesn't match what's configured in your TikTok developer portal. This usually happens if the value in your environment variable (TIKTOK_CLIENT_KEY) is missing, has a typo, or doesn't match the one shown in the TikTok dashboard. Double-check that your clientKey, clientSecret, and callback URL in both your Better Auth config and TikTok portal are exactly the same (including case, no extra spaces, and correct app mode—sandbox vs. live). Also, make sure your callback URL matches TikTok's settings exactly, including protocol and path. Better Auth doesn't validate these values, so any mismatch will only show up as an error from TikTok during login, not earlier in the flow ([source](https://github.com/better-auth/better-auth/blob/93a5a84851c338c2bd238b515e965aae0df18f88/packages/better-auth/src/social-providers/tiktok.ts)). If everything looks correct and you still see the error, try regenerating your TikTok credentials and updating your environment variables. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/8d5f95df-c045-4a32-bb02-54dbf9aadde4?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3258)
Author
Owner

@Kinfe123 commented on GitHub (Aug 10, 2025):

ref - #3114

<!-- gh-comment-id:3172502899 --> @Kinfe123 commented on GitHub (Aug 10, 2025): ref - #3114
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9543