[GH-ISSUE #248] Server action support for auth client #8188

Closed
opened 2026-04-13 03:17:33 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @mmikhan on GitHub (Oct 19, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/248

it seems Server action isn't supported yet for auth client (i.e. signIn, signUp, signOut etc). For example, the following code works:

'use client'

<button
  onClick={async () => {
    await signIn.social({
      provider: "google",
      callbackURL: "/",
    });
  }}
>Sign in with Google</button>

But, the same thing in a server action doesn't. No session is being stored in the database. Similarly, await signOut() doesn't as well.

<form
  action={async () => {
    "use server";
    await signIn.social({
      provider: "google",
      callbackURL: "/",
    });
  }}
>
  <button type="submit">Sign in with Google</button>
</form>

!! Here's an example from Auth.js

Originally created by @mmikhan on GitHub (Oct 19, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/248 it seems Server action isn't supported yet for auth client (i.e. signIn, signUp, signOut etc). For example, the following code works: ```javascript 'use client' <button onClick={async () => { await signIn.social({ provider: "google", callbackURL: "/", }); }} >Sign in with Google</button> ``` But, the same thing in a server action doesn't. No session is being stored in the database. Similarly, `await signOut()` doesn't as well. ```javascript <form action={async () => { "use server"; await signIn.social({ provider: "google", callbackURL: "/", }); }} > <button type="submit">Sign in with Google</button> </form> ``` !! Here's an [example](https://authjs.dev/getting-started/authentication/oauth) from Auth.js
GiteaMirror added the locked label 2026-04-13 03:17:33 -05:00
Author
Owner

@matserix commented on GitHub (Oct 19, 2024):

Already implemented and documented

https://www.better-auth.com/docs/concepts/api#calling-api-endpoints-on-the-server

<!-- gh-comment-id:2424266049 --> @matserix commented on GitHub (Oct 19, 2024): Already implemented and documented https://www.better-auth.com/docs/concepts/api#calling-api-endpoints-on-the-server
Author
Owner

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

That's for when handling auth through an API request where you manually handle everything forward, right? But, what I am referring here is through Social login (could be Credentials login as well) and shall work by simply defining await signIn.social() in a server component

<!-- gh-comment-id:2424783109 --> @mmikhan commented on GitHub (Oct 20, 2024): That's for when handling auth through an API request where you manually handle everything forward, right? But, what I am referring here is through Social login (could be Credentials login as well) and shall work by simply defining `await signIn.social()` in a server component
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8188