skip to Main Content

I realize this is a bit of noob question but im not exactly sure what is the best solution. I have a REACT/Node.js application that is using a Authentication API (Stormpath in this case). The app is working. I have logins for local users as well as social logins for facebook and Google. But my app will have a local database (postgres most likely) where I will need to persist the authenticated user so I can associate things in my application with this user while they are logged in. How should I be doing this, or I guess where should I be doing this? Should my landing page (post login) have some dynamic event (pageload or whatever) that calls some middleware to insert or verify the existing user? Is there a hook I may be missing from my API provider where I can just grab the user. I have looked but have been unable to trigger any middleware rest endpoints I’ve setup in my app from what I think are Auth API endpoints that would provide the user information Im looking for. If I could just get to my middleware I’d have no problem writing the function to insert/verify the user in my local database. I’ve actually already written and tested that so I know it works. I just want a little advice or someone to nudge me in the right direction. I’m working on my own without any help right now so any advice would be greatly appreciated.

FYI I am using the Stormpath-sdk-react.

2

Answers


  1. There are various lifecycle functions in react such as componentWillMount() and componentDidMount(). In componentWillMount() you can hit Api or use local db and check authenticated user and in componentDidMount() you can cancel the request.

    componentWillMount() is invoked before render() and componentDidMount() after render()

    Login or Signup to reply.
  2. You’re not saying which framework you use. If it’s Express then you can use Express-Stormpath. Also when you’re using React then you may want to use stormpath-sdk-react to help you with the API integration. When you get user info in the frontend then you can use it to communicate with your custom endpoint on the backend to store any info that you need. Another way to do that would be to use Stormpath endpoints on your backend and use the data that you get to send it to your frontend. You can do it both ways.

    See:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search