[GH-ISSUE #1743] How to get user info in after hook when sign in by social like Google? #26218

Closed
opened 2026-04-17 16:42:07 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @sangdth on GitHub (Mar 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1743

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I need to access user object, in the magic link method I can get it from ctx.context.newSession, but in /sign-in/social (in my case sign in by Google) the newSession is null.

I'm trying to check documention already but there is no mention of other place than newSession.

Current vs. Expected behavior

I don't know if this is intentional or bug. But

What version of Better Auth are you using?

1.2.3

Provide environment information

- better-auth 1.2.3
- Nextjs 15

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
 database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  emailAndPassword: {
    enabled: true,
  },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    },
  },
hooks: {
    after: createAuthMiddleware(async (ctx) => {
      if (ctx.path.startsWith('/sign-in/social')) {
        const newSession = ctx.context.newSession; <-- null here
...

Additional context

No response

Originally created by @sangdth on GitHub (Mar 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1743 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I need to access `user` object, in the `magic link` method I can get it from `ctx.context.newSession`, but in `/sign-in/social` (in my case sign in by Google) the `newSession` is null. I'm trying to check documention already but there is no mention of other place than newSession. ### Current vs. Expected behavior I don't know if this is intentional or bug. But ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash - better-auth 1.2.3 - Nextjs 15 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), emailAndPassword: { enabled: true, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }, }, hooks: { after: createAuthMiddleware(async (ctx) => { if (ctx.path.startsWith('/sign-in/social')) { const newSession = ctx.context.newSession; <-- null here ... ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 16:42:07 -05:00
Author
Owner
<!-- gh-comment-id:2708747908 --> @sangdth commented on GitHub (Mar 9, 2025): ![Image](https://github.com/user-attachments/assets/9d5f189b-8775-45e6-9e62-2ab4f0088b92) https://discord.com/channels/1288403910284935179/1344618092168220773/1344630814905991169
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26218