Passwordless Authentication in React Native Using Facebook Account Kit (Part 3)
Consuming secure resources from React Native
If you followed the previous steps correctly, you’re almost done. We’re left with making a few modifications on the code we wrote initially in order to register a user on our database and identify him/her upon request.
Integrating the services in our example app
In our React Native application we will implement the following changes:
- Assign the value
http://localhost:3000to the constant API_URL, where our server will be listening. On Android replace the localhost by your local IP address.
- Configure the initial state of our application, with the fields
meset to null.
- Create a method getJWT to request a JWT from the server based on the code that we obtained from Account Kit, using the fetch method for the request and storing the result in the
- Modify the render of the component to display the JWT we obtained, hide the Login button and enable the Get Profile and Exit buttons when the value of the
jwthas been assigned.
- Create a method handleGetMePress to retrieve a user profile by sending the JWT we previously obtained as a request header. The result will be stored on the state as
- And finally, modify the render method in order to display the phone number we received on the previous step.
The resulting code will be:
Done! You should be able to run the example and see the following result on your app:
If you liked this series of posts don’t hesitate to comment and share. If you have doubts or ran into trouble on any of the steps, please comment below, we are glad to provide help to any member of the global React Native community.
Passwordless Authentication Using Facebook Account Kit
If you’re looking for React Native experts, don’t hesitate to contact us! Write to us from our web or send us an e-mail at firstname.lastname@example.org.