Auth0 Home Blog Docs

Post Current User data to a database



I’m building a web app where I want to be able to store the current user’s user_id to a table in my database. How would I go about getting that data on my front-end in order to send it to my back-end? I’m using React, Express, and Postgres.

The idea is a user will log in through auth0. They’ll be able to see what they’ve posted to my database, if anything. React will send whatever data they post (including their auth0 user_id) to my express server, which will save it to my database.


Found it on my own, the key was to write this into my componentDidMount method. const { userProfile, getProfile } = this.props.auth; if (!userProfile) { getProfile((err, profile) => { this.setState({ profile: profile, dataLoaded: true, }); }); } else { this.setState({ profile: userProfile, dataLoaded: true, }); }