Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store custom user data on Netlify Identity?

I've been using Netlify for storing 100% of my app (both frontend and backend) for the last three months. So far, so good.

The only problem now is that I need to store a custom property for each user (say, the phone number), and apparently Netlify Identity doesn't support this (only email, name and roles https://www.netlify.com/docs/identity/).

I don't want to change the whole app to migrate to another hosting provider just for this detail (actually, I can't, it's for a client and I just don't have time), because it works great, but at the same time I need it.

Can you think of any workaround to this? The less "hackish", the better, but I understand that I'm going beyond the intended use of Netlify Identity.

like image 939
Jose Avatar asked Sep 04 '18 21:09

Jose


2 Answers

So it actually does look like Netlify's GoTrue API has a specific endpoint for updating custom user data. After a user is created, you can update metadata by including it as "data" within an authenticated PUT request to /user.

PUT /user

{
  "data" {
    "custom_key": "value",
  }
}

See https://github.com/netlify/gotrue for more info.

like image 122
KMcAloon Avatar answered Nov 14 '22 04:11

KMcAloon


There are dozens of ways to do this, so I'll talk about two generally applicable ways now:

  • the most "generally capable" one is probably using lambda functions: https://www.netlify.com/docs/functions . This lets you run dynamic code, such as "store to database hosted elsewhere" or "email to our office manager to update a spreadsheet" or even "commit to our closed git repo so it's available in-code" (last one is probably a worst practice, but is possible). You can similarly use a function to read that data back out without exposing API tokens (code example: https://github.com/netlify/code-examples/tree/master/function_examples/token-hider)

  • you could have the data gathered via a form submission (https://www.netlify.com/docs/form-handling). I'd probably use zapier.com to receive a notification of the form submission (https://www.netlify.com/docs/form-handling/#notifications). Zapier can of course connect to just about anything on the planet :) . Getting the data back out if you want to show it in your UI is a bit more of a challenge, but you could use the above mentioned functions if you need to connect to some private data store to pull it out. Or for an MVP, just not show it, only let people enter/update it ;)

like image 34
fool Avatar answered Nov 14 '22 02:11

fool