oAuth & Database?

Hello,

I have implemented my oAuth using the guide you have for Vue. It works and I have built a profile page (horrah!) Currently it only shows the data i get back after logging in but it’s a start.

On my profile page I have a form which users can enter words to be saved to a database (I understand how to do the CRUD operations) but how do i do that? Since i need to have the words attatched to a user ID, but how do i push a userId to a database? In which part of the flow?

Hello @Plainnn,

This is pretty generic advice, but I hope it helps: you are going to want to have a common and unique key between your user profiles in Auth0 and the database where you are storing the text entered by the user. You can use the Auth0 user_id field as a unique key, though personally I prefer to generate my own unique identifier with an Auth0 rule. For example:

Whatever identifier you decide to use from Auth0, you can use a rule to include that attribute in your idToken and / or access token, which your app can then use to populate the database.

1 Like

Hey that works, thanks a lot. How do i now send this UUID to my database?

I’m afraid those details are a bit beyond me (I’m not a developer). WHatever development environment you are using likely has libraries for talking to your database solution. Once you’ve created the UUID and added it to your idToken it will be available in your app for sending to your database.

Sorry, I should’ve been more clear, i actually mean how do i add it to my ID token, currently i get nickname, name, picture, updated at etc…

That part I can help with! Again you can use a rule, one that runs after the UUID rule, which adds profile data to the idToken and / or access token. Something like (this super basic code has not been tested):

function (user, context, callback) {
// Adds app_metadata.uuid to the idToken
  var namespace = "https://yourdomain.com/claims/";
  context.idToken[namespace + "uuid"] = user.app_metadata.uuid || ""; 
  callback(null, user, context);
}

You might want to make that smarter by checking for the presence of the UUID attribute rather than blindly assigning something.

1 Like

Do also note the namespace is required. It has to be generally like so http(s)://(namespace).TLD(/optional further namespacing)/(claimId)

I say this because I was confused myself. I tried things like pt:// (a custom scheme I use to refer to my services internally) and this did not work, and it also did not work when omitting the TLD. I ended up just using my normal production domain as the namespace and then it did work.

1 Like

Unreal, you don’t understand how much this helps! I would like to know if it possible to find this info in the docs/guides you have. I’ve been looking forever and couldn’t work it out! Maybe i’m just too new too this ^^

1 Like

The Auth0 docs are extensive (~800,000 words last time I checked), and there’s a lot of great material in there, though it can be hard to find what you need. The platform is evolving rapidly so I am sure it is difficult to keep it all up to date and organized.

Be sure to check the blog because many of the Auth0 content engineer folks write super detailed posts like this:

Blog:

1 Like

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