We've moved discussions to Discord

Best way to programmatically generate an API token when a new User is created?

Brian Carpenter
I'd like to generate an API token automatically when a new User signs up.

My thought was to call the ApiToken.generate_token model method in an after_create callback in the User model.

Just wondering if anyone else is doing this and if there's a better way.


Nicholas B
Yeah I think this would be the way to go about it.

- Maybe after_commit?


Brian Carpenter
Thanks, I spent some time poking around and I think that would work.  But, I then found this jumpstart tutorial which walks through the mechanics of creating child model inserts on signup and just replicated the process for what I needed.
Nicholas B
Wow that's really helpful, thanks :)
Notifications
You’re not receiving notifications from this thread.