i configured login with github but i keep getting the redirecturi issue #87

Closed
opened 2026-03-13 07:32:34 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @firstaxel on GitHub (Oct 17, 2024).

Screenshot from 2024-10-17 12-55-13

this is the auth config

import { hash, verify } from "argon2";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

import { db } from "@acme/db/client";

import { env } from "../env";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),

  emailAndPassword: {
    enabled: true,
    sendEmailVerificationOnSignUp: true,
    password: {
      hash,
      verify,
    },
  },
  socialProviders: {
    github: {
      clientId: env.GITHUB_CLIENT_ID,
      clientSecret: env.GITHUB_CLIENT_SECRET,
      redirectURI: "http://localhost:3000/api/auth/callback/github",
    },
  },
});

authclient

import { env } from "@/env";

import { createAuthClient } from "@acme/auth";

export const { signIn, signUp, useSession } = createAuthClient({
  baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
});

Originally created by @firstaxel on GitHub (Oct 17, 2024). ![Screenshot from 2024-10-17 12-55-13](https://github.com/user-attachments/assets/e900070f-9c16-4be6-90e8-7c7b712a6bc1) this is the auth config ``` import { hash, verify } from "argon2"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@acme/db/client"; import { env } from "../env"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, sendEmailVerificationOnSignUp: true, password: { hash, verify, }, }, socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, redirectURI: "http://localhost:3000/api/auth/callback/github", }, }, }); ``` authclient ``` import { env } from "@/env"; import { createAuthClient } from "@acme/auth"; export const { signIn, signUp, useSession } = createAuthClient({ baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL, }); ```
Author
Owner

@firstaxel commented on GitHub (Oct 17, 2024):

Screenshot from 2024-10-17 13-18-11

this is my github setup

for the social auth click

  await signIn.social({
                provider: "github",
                callbackURL: "/dashboard",
              });

with tanstack usemutation

  const { mutate: oauthSignIn, isPending: isPendingOAuthSignIn } = useMutation({
    mutationKey: ["signIn_Oauth"],
    mutationFn: async (
      oauth:
        | "github"
        | "apple"
        | "discord"
        | "facebook"
        | "google"
        | "microsoft"
        | "spotify"
        | "twitch"
        | "twitter",
    ) => {
      await signIn.social({
        provider: oauth,
        callbackURL: "/dashboard",
      });
    },
  });
@firstaxel commented on GitHub (Oct 17, 2024): ![Screenshot from 2024-10-17 13-18-11](https://github.com/user-attachments/assets/b23a0f1d-de7b-4703-919c-a223271e9803) this is my github setup for the social auth click ``` await signIn.social({ provider: "github", callbackURL: "/dashboard", }); ``` with tanstack usemutation ``` const { mutate: oauthSignIn, isPending: isPendingOAuthSignIn } = useMutation({ mutationKey: ["signIn_Oauth"], mutationFn: async ( oauth: | "github" | "apple" | "discord" | "facebook" | "google" | "microsoft" | "spotify" | "twitch" | "twitter", ) => { await signIn.social({ provider: oauth, callbackURL: "/dashboard", }); }, }); ```
Author
Owner

@firstaxel commented on GitHub (Oct 17, 2024):

i tried with google everything works perfectly and i get redirected i dont know why github is having the issue, i tried the google sign in with tanstack query it works perfectly also

@firstaxel commented on GitHub (Oct 17, 2024): i tried with google everything works perfectly and i get redirected i dont know why github is having the issue, i tried the google sign in with tanstack query it works perfectly also
Author
Owner

@firstaxel commented on GitHub (Oct 18, 2024):

@Bekacru please respond

@firstaxel commented on GitHub (Oct 18, 2024): @Bekacru please respond
Author
Owner

@Bekacru commented on GitHub (Oct 18, 2024):

first you don't need to pass redirectURI it should be infered from your base url. and make sure your redirect url is correct in github and you're using the correct client id.

@Bekacru commented on GitHub (Oct 18, 2024): first you don't need to pass `redirectURI` it should be infered from your base url. and make sure your redirect url is correct in github and you're using the correct client id.
Author
Owner

@firstaxel commented on GitHub (Oct 20, 2024):

Fixed, I think it is wrong configuration

@firstaxel commented on GitHub (Oct 20, 2024): Fixed, I think it is wrong configuration
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#87