How do I access the user's email when they signed up with google
How do I access the user's email when they signed up with google, the email column is null when they signed up with google
8 Replies
Hi @haarismian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To access the user's email when they sign up with Google, you need to use the
getEmail
helper function provided by Wasp. This function returns the user's email or null
if the user doesn't have an email auth identity. Here is how you can use it:
However, if the email column is null when they signed up with Google, it might be because you didn't specify the email
scope in the configFn
function. By default, Wasp doesn't store any information it receives from the social login provider. It only stores the user's ID specific to the provider. If you want to get the user's email, you need to specify the email
scope in the configFn
function.
Here is an example of how to do it:
This will request the user's email from Google during the authentication process.
For more details, you can refer to the Wasp documentation on Google Authentication (https://wasp-lang.dev/docs/auth/social-auth/google#overrides) and Accessing the Auth Fields (https://wasp-lang.dev/docs/auth/entities#accessing-the-auth-fields).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai if I want to create a posthog event when the user signs up with google, where should I do that
Let me check the knowledge base for you. One moment! :books:
Wohooo @haarismian, you just became a Waspeteer level 5!
----------------------
Currently, Wasp doesn't provide
onLogin
and onSignup
hooks, so there isn't a direct way to run some code on signup or on login. This feature is on their radar and they plan to work on it in the future as mentioned in this Github issue (https://github.com/wasp-lang/wasp/issues/1556).
As an alternative, you can create a custom job that runs each minute and checks the list of users in your Wasp DB. When a new user is detected, you can then create a Posthog event. However, please note that the lowest resolution for these jobs is 1 minute.
Here is an example of how you might set up such a job:
In the checkNewUsers.js
file, you would then implement the logic to check for new users and create a Posthog event.
Please note that this is a workaround and might not be suitable for all use cases, especially if you need real-time data. For more information on jobs in Wasp, you can refer to the Wasp documentation on Jobs (https://wasp-lang.dev/docs/advanced/jobs).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Kapa is wrong here
There is an after signup hook: https://wasp-lang.dev/docs/auth/auth-hooks#executing-code-after-the-user-signs-up
Auth Hooks | Wasp
Auth hooks allow you to "hook into" the auth process at various stages and run your custom code. For example, if you want to forbid certain emails from signing up, or if you wish to send a welcome email to the user after they sign up, auth hooks are the way to go.
@miho thanks for sharing that link you are the best!