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!
No description
Solution:
All good, I resolved my issue by using ctx.context.newSession and ctx.redirect 👍
No description
Jump to solution
2 Replies
Ping
Ping4w ago
I don't think this is accessible there, since that endpoint is just to redirect to the callback url. What do you want to do with user info?
Solution
Aymeric
Aymeric4w ago
All good, I resolved my issue by using ctx.context.newSession and ctx.redirect 👍
No description

Did you find this page helpful?