Is it possible to sign up with OAuth using Better Auth? #1015

Closed
opened 2026-03-13 08:17:52 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @ledihildawan on GitHub (Apr 9, 2025).

I couldn't find a 'signUp with social' function when using authClient. Is there any reference I could use as a guide? Thank you.

Originally created by @ledihildawan on GitHub (Apr 9, 2025). I couldn't find a 'signUp with social' function when using authClient. Is there any reference I could use as a guide? Thank you.
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

I've only managed to reach the email login stage, but when I log in, I don't get an 'email not found' error. I thought it would create a new account automatically.

@ledihildawan commented on GitHub (Apr 9, 2025): I've only managed to reach the email login stage, but when I log in, I don't get an 'email not found' error. I thought it would create a new account automatically.
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

try {
  const res = await authClient.signUp.email({
    name: event.currentTarget.name.value,
    email: event.currentTarget.email.value,
    username: event.currentTarget.username.value,
    password: event.currentTarget.password.value,
  });

  if (res.data) {
    router.push("/sign-in");
  }
} catch (error) {
  console.error(error);
} finally {
  setIsLoading(false);
}
@ledihildawan commented on GitHub (Apr 9, 2025): ```TS try { const res = await authClient.signUp.email({ name: event.currentTarget.name.value, email: event.currentTarget.email.value, username: event.currentTarget.username.value, password: event.currentTarget.password.value, }); if (res.data) { router.push("/sign-in"); } } catch (error) { console.error(error); } finally { setIsLoading(false); } ```
Author
Owner

@Kinfe123 commented on GitHub (Apr 9, 2025):

yeah i think When a user signs in with OAuth for the first time, Better Auth automatically creates a new account unless you mention a flag called disableImplicitSignUp is set to true. it is flag that controls the bevaiour on a newly signed user via oauth

here is how you do it -

socialProviders: {
  google: {
    clientId: "YOUR_GOOGLE_CLIENT_ID",
    clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
    disableImplicitSignUp: true, // Requires explicit sign-up request
  }
}
@Kinfe123 commented on GitHub (Apr 9, 2025): yeah i think When a user signs in with OAuth for the first time, Better Auth automatically creates a new account unless you mention a flag called `disableImplicitSignUp` is set to true. it is flag that controls the bevaiour on a newly signed user via oauth here is how you do it - ```ts socialProviders: { google: { clientId: "YOUR_GOOGLE_CLIENT_ID", clientSecret: "YOUR_GOOGLE_CLIENT_SECRET", disableImplicitSignUp: true, // Requires explicit sign-up request } } ```
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

I received a message like this:
2025-04-09T15:05:49.434Z ERROR [Better Auth]: Provider did not return email. This could be due to misconfiguration in the provider settings.
I am using ElysiaJS and Next.js separately, here's my files:

// auth.ts (server)

export const auth = betterAuth({
  plugins: [openAPI({ disableDefaultReference: true }), username(), nextCookies(), oAuthProxy()],
  account: {
    accountLinking: {
      enabled: true,
    },
  },
  database: drizzleAdapter(db, {
    schema,
    provider: 'pg',
  }),
  emailAndPassword: {
    enabled: true,
    autoSignIn: false,
  },
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID as string,
      clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
      disableImplicitSignUp: false,
    },
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
      disableImplicitSignUp: false,
    },
  },
  trustedOrigins: [WEB_URL],
});
// auth.ts (web)

export const authClient = createAuthClient({
  baseURL: "http://localhost:44720",
  plugins: [usernameClient()],
});

My goal is that when a user creates an account and signs up using their provider, they will automatically be redirected to a specific page, and their data will be stored in the database. Are there any methods I might have missed based on what I have already set up?

@ledihildawan commented on GitHub (Apr 9, 2025): I received a message like this: ` 2025-04-09T15:05:49.434Z ERROR [Better Auth]: Provider did not return email. This could be due to misconfiguration in the provider settings. ` I am using ElysiaJS and Next.js separately, here's my files: ```TS // auth.ts (server) export const auth = betterAuth({ plugins: [openAPI({ disableDefaultReference: true }), username(), nextCookies(), oAuthProxy()], account: { accountLinking: { enabled: true, }, }, database: drizzleAdapter(db, { schema, provider: 'pg', }), emailAndPassword: { enabled: true, autoSignIn: false, }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID as string, clientSecret: process.env.GITHUB_CLIENT_SECRET as string, disableImplicitSignUp: false, }, google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, disableImplicitSignUp: false, }, }, trustedOrigins: [WEB_URL], }); ``` ```TS // auth.ts (web) export const authClient = createAuthClient({ baseURL: "http://localhost:44720", plugins: [usernameClient()], }); ``` My goal is that when a user creates an account and signs up using their provider, they will automatically be redirected to a specific page, and their data will be stored in the database. Are there any methods I might have missed based on what I have already set up?
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

yeah i think When a user signs in with OAuth for the first time, Better Auth automatically creates a new account unless you mention a flag called disableImplicitSignUp is set to true. it is flag that controls the bevaiour on a newly signed user via oauth

here is how you do it -

socialProviders: {
google: {
clientId: "YOUR_GOOGLE_CLIENT_ID",
clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
disableImplicitSignUp: true, // Requires explicit sign-up request
}
}

Yes, that's correct. I've tried it and saw that the user data is stored in the table. However, when I try to log in again, the provider informs me that the user is not found, including with GitHub.

@ledihildawan commented on GitHub (Apr 9, 2025): > yeah i think When a user signs in with OAuth for the first time, Better Auth automatically creates a new account unless you mention a flag called `disableImplicitSignUp` is set to true. it is flag that controls the bevaiour on a newly signed user via oauth > > here is how you do it - > > socialProviders: { > google: { > clientId: "YOUR_GOOGLE_CLIENT_ID", > clientSecret: "YOUR_GOOGLE_CLIENT_SECRET", > disableImplicitSignUp: true, // Requires explicit sign-up request > } > } Yes, that's correct. I've tried it and saw that the user data is stored in the table. However, when I try to log in again, the provider informs me that the user is not found, including with GitHub.
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

// page.tsx

async function onSignUpWithGitGoogle(event: FormEvent<HTMLButtonElement>) {
  setIsLoading(true);

  try {
    const res = await authClient.signIn.social({
      provider: "google",
    });
    
  } catch (error) {}
}
@ledihildawan commented on GitHub (Apr 9, 2025): ```TS // page.tsx async function onSignUpWithGitGoogle(event: FormEvent<HTMLButtonElement>) { setIsLoading(true); try { const res = await authClient.signIn.social({ provider: "google", }); } catch (error) {} } ```
Author
Owner

@Kinfe123 commented on GitHub (Apr 9, 2025):

you only needing google oauth or what are you actually planning to do ?

@Kinfe123 commented on GitHub (Apr 9, 2025): you only needing google oauth or what are you actually planning to do ?
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

you only needing google oauth or what are you actually planning to do ?

First, I'm just learning, and I see this library is really complete and open source. I want to try implementing sign-up using Google and GitHub accounts. I haven't found many tutorials on YouTube yet. For now, just these two websites, before trying others. I've also created the Client ID and Client Secret. And I saw in the documentation that the tutorial only has the method authClient.signIn.social, but I thought there would be authClient.signUp.social.

@ledihildawan commented on GitHub (Apr 9, 2025): > you only needing google oauth or what are you actually planning to do ? First, I'm just learning, and I see this library is really complete and open source. I want to try implementing sign-up using Google and GitHub accounts. I haven't found many tutorials on YouTube yet. For now, just these two websites, before trying others. I've also created the Client ID and Client Secret. And I saw in the documentation that the tutorial only has the method `authClient.signIn.social`, but I thought there would be `authClient.signUp.social`.
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

So, when the user successfully registers or logs into the app using their social media account, I will delete that data and try with another social media account. That's my goal.

@ledihildawan commented on GitHub (Apr 9, 2025): So, when the user successfully registers or logs into the app using their social media account, I will delete that data and try with another social media account. That's my goal.
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

you only needing google oauth or what are you actually planning to do ?

It turns out that Google works safely, previously because I didn't provide the callback URL. GitHub has a message saying that the email was not found.

Better Auth Error
We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists.
Return to Application
Error Code: email_not_found
@ledihildawan commented on GitHub (Apr 9, 2025): > you only needing google oauth or what are you actually planning to do ? It turns out that Google works safely, previously because I didn't provide the callback URL. GitHub has a message saying that the email was not found. ``` Better Auth Error We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists. Return to Application Error Code: email_not_found ```
Author
Owner

@ledihildawan commented on GitHub (Apr 9, 2025):

@Kinfe123 successfully signed up via GitHub, I just need to recreate the Client ID and Client Secret in Developer Settings, thanks.

@ledihildawan commented on GitHub (Apr 9, 2025): @Kinfe123 successfully signed up via GitHub, I just need to recreate the Client ID and Client Secret in Developer Settings, thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1015