[GH-ISSUE #1512] How to identify signup event from github and magic links via hooks. #8797

Closed
opened 2026-04-13 04:00:18 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @opswiz on GitHub (Feb 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1512

When user uses magic links or signin with github/google for first time, they are signed up. With hooks how do we distinguish between regular login events and signup events.

The newSession is used as reference for email signup in examples, but this seems the newSession is created after every run https://www.better-auth.com/docs/concepts/hooks#new-session and using that, unable to determine signup.

Expectation is to record signup events, track user signups or notify few things via email once.

Originally created by @opswiz on GitHub (Feb 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1512 When user uses magic links or signin with github/google for first time, they are signed up. With hooks how do we distinguish between regular login events and signup events. The newSession is used as reference for email signup in examples, but this seems the newSession is created after every run https://www.better-auth.com/docs/concepts/hooks#new-session and using that, unable to determine signup. Expectation is to record signup events, track user signups or notify few things via email once.
GiteaMirror added the locked label 2026-04-13 04:00:18 -05:00
Author
Owner

@drithh commented on GitHub (Feb 21, 2025):

+1

<!-- gh-comment-id:2673863959 --> @drithh commented on GitHub (Feb 21, 2025): +1
Author
Owner

@Bekacru commented on GitHub (Feb 25, 2025):

You can either use database hooks or you can check the user createdAt date to determine.

<!-- gh-comment-id:2680992150 --> @Bekacru commented on GitHub (Feb 25, 2025): You can either use [database hooks ](https://www.better-auth.com/docs/concepts/database#database-hooks) or you can check the user `createdAt` date to determine.
Author
Owner

@opswiz commented on GitHub (Feb 25, 2025):

Nice, database hooks works. Apologies, I missed it.

Not sure what you refer to by checking createdAt time, by following timestamp might endup in a uncertain workflow i guess.

but still, It was still difficult to identify how the user is signed up though. I tried manually querying accounts for user to find it, but by the time databaseHooks.user.create.after hook is fired, the account seems to be not created yet by then, so unable to identify user.

One other option I thought of is introducing a forced delay after the hook is called then query or put them in a queue to execute asynchronously afterwards. but both are just workarounds(which works).

Any thoughts on this @Bekacru ?

<!-- gh-comment-id:2681402489 --> @opswiz commented on GitHub (Feb 25, 2025): Nice, database hooks works. Apologies, I missed it. Not sure what you refer to by checking createdAt time, by following timestamp might endup in a uncertain workflow i guess. but still, It was still difficult to identify how the user is signed up though. I tried manually querying accounts for user to find it, but by the time databaseHooks.user.create.after hook is fired, the account seems to be not created yet by then, so unable to identify user. One other option I thought of is introducing a forced delay after the hook is called then query or put them in a queue to execute asynchronously afterwards. but both are just workarounds(which works). Any thoughts on this @Bekacru ?
Author
Owner

@amosbastian commented on GitHub (Feb 26, 2025):

@opswiz You can check if the user was created recently (e.g. in the last minute), then do the signup event tracking

<!-- gh-comment-id:2686279426 --> @amosbastian commented on GitHub (Feb 26, 2025): @opswiz You can check if the user was created recently (e.g. in the last minute), then do the signup event tracking
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8797