Generate Oauth/Social sign in links server side

I'm just getting started with better-auth and have what might be a basic question.

I want to generate a sign in link on my server. What is the correct API method to do that?

e.g. I want a URL for a "sign in to google" button that I can include in my server side template (either in a form as the form action, or as a link URL)
Solution
You do need to follow the setup guide for the authentication provider you wish to use: https://www.better-auth.com/docs/authentication/google

all client calls can be access on the auth.api and the options you would usally pass to the client call like:

const data = await authClient.signIn.social({
  provider: "google",
  idToken: {
    token: // Google ID Token,
    accessToken: // Google Access Token
  }
})


becomes

const data = await auth.signInSocial({
  headers: headers, // you need to pass in the request headers
  body:{
    provider: "google",
    idToken: {
      token: // Google ID Token,
      accessToken: // Google Access Token
    }
  }
})


see more documentation here
Google provider setup and usage.
Better Auth API.
Was this page helpful?