Distinguished if the user was created or if they already existed with a magic link
I would like to perform some actions once the user has been created via a Magic Link, for example sending a welcome email and initializing other resources in other domains.
However, I don't see how to distinguish between creation and reading in an after_action. According to my tests, the values of the parameters are identical in both cases. Any ideas?
Solution:Jump to solution
Here is what works for me:
```
upsert_fields [:email, :last_signed_in_at]
...
8 Replies
Right now the only way is to compare the inserted at and updated at timestamps
Mhhh, when log in, the updated_at field does not seems to be updated
Ah, right you are
🤔 I mean, its hacky, but you could see if the user was "just created"
I added the "updated_at" field into the
upsert_fields
and it seems to work. upsert_fields [:email, :updated_at]
I think that means you're updating the user every time they sign in
you may want to add a
last_signed_in_at
and set that in the sign in actionIndeed, that appears to be cleaner. I'll try that.
Solution
Here is what works for me:
In my case the only way of register is via magic link so the field can never be empty, at least at the moment.
Thanks for helping me!
🥳