Summary
Clicking Sign in with GitHub shows GitHub’s warning page: Be careful! The redirect_uri is not associated with this application. Inspecting the authorize request shows Better Auth is sending redirect_uri=%2Fcallback%2Fgithub, i.e. a relative path.
I’m attempting to follow the next-auth migration guide and believe I’ve successfully set it up. However, for some reason, my redirect URI is invalid. I’m at a loss as to what’s causing this issue. I’ve tried using incognito mode, different browsers, and clearing my cache, but none of these methods seem to resolve the problem. I’ve configured my next app with the URL NEXT_PUBLIC_APP_URL=http://localhost:3000. Both Google and GitHub are configured to http://localhost:3000/api/auth/callback/google and http://localhost:3000/api/auth/callback/github, respectively, through their OAuth configurations.
https://github.com/login/oauth/authorize?response_type=code&client_id=${clientId}&scope=read%3Auser+user%3Aemail&redirect_uri=%2Fcallback%2Fgithub
Because the redirect URI no longer matches the fully qualified URL we have registered in the GitHub OAuth app, GitHub blocks the flow.
Actual Behavior
- GitHub rejects the OAuth request, warning that the supplied
redirect_uri is not associated with the application because Better Auth encoded /callback/github instead of an absolute URL.
- Attempting to sign in with Google now yields
Access blocked: Authorization Error – Error 400: invalid_request with redirect_uri=/callback/google and flowName=GeneralOAuthFlow, so both providers appear to be affected by the relative redirect.
Expected Behavior
Better Auth should send the fully qualified callback URL (e.g. https://localhost:3000/api/auth/callback/{provider}, matching the value registered with the provider), so the OAuth exchange can finish successfully.
Relevant Configuration
// src/lib/auth.ts
import { betterAuth } from "better-auth";
...
export const auth = betterAuth({
...
socialProviders: {
github: {
clientId: config.AUTH_GITHUB_ID!,
clientSecret: config.AUTH_GITHUB_SECRET!,
// redirectUri: "http://localhost:3000/api/auth/callback/github",
},
google: {
clientId: config.AUTH_GOOGLE_ID!,
clientSecret: config.AUTH_GOOGLE_SECRET!,
},
},
plugins: [nextCookies()],
});
Because the explicit redirectUri is commented out, Better Auth appears to fall back to /callback/{provider} rather than inferring the deployed base URL. GitHub rejects the relative path immediately, and Google now responds with invalid_request.
Additional Context
- Browser: Chrome 131.0.6778.265
- OS: macOS 15.1 (Apple Silicon)
Summary
Clicking Sign in with GitHub shows GitHub’s warning page:
Be careful! The redirect_uri is not associated with this application.Inspecting the authorize request shows Better Auth is sendingredirect_uri=%2Fcallback%2Fgithub, i.e. a relative path.I’m attempting to follow the next-auth migration guide and believe I’ve successfully set it up. However, for some reason, my redirect URI is invalid. I’m at a loss as to what’s causing this issue. I’ve tried using incognito mode, different browsers, and clearing my cache, but none of these methods seem to resolve the problem. I’ve configured my next app with the URL NEXT_PUBLIC_APP_URL=http://localhost:3000. Both Google and GitHub are configured to http://localhost:3000/api/auth/callback/google and http://localhost:3000/api/auth/callback/github, respectively, through their OAuth configurations.
Because the redirect URI no longer matches the fully qualified URL we have registered in the GitHub OAuth app, GitHub blocks the flow.
Actual Behavior
redirect_uriis not associated with the application because Better Auth encoded/callback/githubinstead of an absolute URL.Access blocked: Authorization Error – Error 400: invalid_requestwithredirect_uri=/callback/googleandflowName=GeneralOAuthFlow, so both providers appear to be affected by the relative redirect.Expected Behavior
Better Auth should send the fully qualified callback URL (e.g.
https://localhost:3000/api/auth/callback/{provider}, matching the value registered with the provider), so the OAuth exchange can finish successfully.Relevant Configuration
Because the explicit
redirectUriis commented out, Better Auth appears to fall back to/callback/{provider}rather than inferring the deployed base URL. GitHub rejects the relative path immediately, and Google now responds withinvalid_request.Additional Context