Setting custom user data right after register

Im working on an app where a user can signup and add personal information (such as address, date of birth, etc.). I then register them via the email/password auth. Since the app is targeted for the german market I then use custom functions to send confirmation emails. So far so good. I now need to safe the custom date somehow when the user registers. Is there a way to save the custom user data as soon as I register the user and they are not yet confirmed, aka. pending? What is the best practice in this case?

3 Likes

Hi @Benedikt_Bergenthal,

Did you find a solution to the problem? we are also having a similar requirement where we ask for 3 information while registering.

  1. Name
  2. email
  3. password

the realm “register” function takes only “email” and “password”. We need to store the name in custom data object, untill the user confirm confirm the email and status changes from “pending” to “authenticated”.

1 Like

How I’d handle this would be to login with anonymous login after registration. You can then call a Realm function (that you write) to store the name ane email address in Atlas. You can then add an authentication trigger to run when the user is confirmed (the trigger should be registered against “CREATE” authentication events). The function associated with that trigger can then link the new user to the data that was anonymously added via the Realm function.

You can also link the anonymous user with the user that you’re registering – this is how it’s done on iOS: https://docs.mongodb.com/realm/sdk/ios/advanced-guides/link-user-identities/

2 Likes

I’m currently storing the additional infos in a cache DB using a custom API. When the user logs in for the first time using their account I use a trigger to transfer the data to the user and delete it from the cache.
Not very elegant, but it works. :wink:

1 Like

Can you please expand more on this idea, i know its late but m having trouble implementing this, how would you be able to store the other user data such as username, date of birth etc when atlas does not allow you to insert until the user email is verified?

@Dyonis_N_A

A question:

Why capture a bunch of user information and store it, with the possibility the authentication may fail - or it could be a fake user? That just takes up bandwidth, space and increases your cost.

I would suggest having a user register first, then upon success, capture their user information and store it.

It’s a more streamlined process and will cost (you) less.

Thank you for your response. I’ve been contemplating the following user flow and would appreciate your confirmation on its viability:

After a user provides their email and password during the registration process, I propose introducing an “Email Verification Page.” This page would feature a straightforward prompt instructing users to check their email. Additionally, it should include a button allowing users to resend the confirmation email in case it expires or isn’t received.

Furthermore, I’d like to inquire if there’s a way to:

  1. Determine whether a user’s email has been verified.
  2. Check if a user has been successfully added to MongoDB Atlas.

Thank you once again for your assistance.

That sounds like a better workflow.

The answer to both questions is yes, and there are about 100 solutions to that as well.

You can execute server side code when a user authenticates or have it add an entry to your database which your app is observing. The server and your app can perform a variety of tasks when events happen - just depends on your use case.