Better AuthBA
Better Authβ€’9mo ago
Aymeric

How to access user email or userId in social login hook (Google/Microsoft)?

Hi everyone! πŸ‘‹
I’m trying to handle user logins using Google and Microsoft in BetterAuth.

In the after hook of createAuthMiddleware, I want to check some conditions based on the user’s email or userId, like I already do for regular email sign-in (see screenshot).

However, during the /callback/:id route (social login), I’m not sure how to retrieve the email or userId of the user trying to log in. Is it possible to access that information in a before or after hook?

Any pointers or examples would be greatly appreciated πŸ™
Thanks in advance!
image.png
Solution
All good, I resolved my issue by using ctx.context.newSession and ctx.redirect πŸ‘
image.png
Was this page helpful?