Current User
After implementing user registration and login to your, you need to retrieve the currently logged user data to perform different actions and requests. This data can be promptly retrieved by using Parse.User.current inside your app components.
To complete this tutorial, you will need:
- Complete the previous guide so you can have a better understanding of the Parse.User class and the Parse.User.logIn method
- If you want to test/use the screen layout provided by this guide, you should set up the Ant Design library.
Get the current user data fetching using Parse for a React app.
The method Parse.User.current can be used anywhere on your code, after properly configuring your app to use Parse. Its response will be your current user’s object (Parse.User) or null if there is no logged-in user currently.
This method is essential in situations where you don’t have access to your application state or your user data, making it possible to perform relevant Parse requests in any component of your app.
In our previous guides, the Parse.User.current method was already used for testing showing the current username on the User Login guide. Here is the UserLogin component code, take a closer look at the getCurrentUser function:
In this component, the Parse.User.current method retrieves the username and updates the state variable that is rendered inside the component JSX. Add these classes to your App.css file to fully render the layout styles:
At the end of this guide, you learned how to retrieve the current Parse user data from local storage on React. In the next guide, we will show you how to enable your user to reset his password.