Customizing user_id on signup

I would like to customize the user_id on signup, more specifically I would like to use a BSON.ObjectId.

I’ve found a way to do this through the management API by simply passing a user_id in the request body. However, this doesn’t seem to work for users that are created through the social media connections (via oauth).

Another way that I’ve found is to use the Pre User Registration hook, in which I could set the response.user.id or as an alternative I could also set an additional id in the user_metadata in this hook… however both ways don’t seem to work for the social media connections.

Is there a way to accomplish this that also works for the social connections?

Hi @robinv,

Welcome to the Community!

That is correct, this will not work for social. Hooks only work for DB connections.

If you want to do this after first login for social and db users you must do it via a rule. You could check for a flag in app_metadata, and if it doesn’t exist then change the user_id via a call to the management API then set the flag.

With that said, you might be able to avoid setting a new user id, which could be fairly complicated. Typically, you will set any external id in the app_metadata and then add that id to the token in a custom claim via a rule.

Let me know if you have questions,
Dan

1 Like

Alright, thanks for the quick reply @dan.woda!
I went with the app_metadata solution and a rule, seems to work quite well.

2 Likes

Glad it is working for you! Cheers!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.