0

I would like to have your proper opinions about my following situation:

Server-side: I have a backend API implemented using Express JS on NodeJS. The authentication system is based on JWT token-based implementation using Passport. I have also used FacebookStrategy for social authentication. The controller returns the token as a successful response for both social and local authentication.

Client-side: As the frontend of the project, I am using ReactJS. For social authentication, I have put a Link to a Route pointing to the URL for Facebook callback URL from my backend API which returns JWT token as a response. When we click to the link, it successfully redirects to the Facebook login page. After I filled the credentials and got login, it returns the JSON response containing the token in the page.

My concern: How can I obtain the token while I am using the Link to the backend API from client-side code?

Thank you in advance.

  • What is the issue here? You said you are already getting the JSON response with token, please clarify – MiKr13 Aug 13 '19 at 20:45
  • The problem: I am clicking to a link which redirects to Facebook callback URL in the backend, which returns the token as a response, and I see the response from the backend on the browser: but i want to access/use the response in the client-side. I am not using axios or fetch functions. Request is done using a link. – Fuad Aghazada Aug 13 '19 at 20:52

1 Answers1

0

This is not possible my friend, JS can't access current page header or response, you can use AJAX to catch the response and headers and what not but not by JS for the current page. If you wanted the URL then it's accessible using: windows.location It'll give you much information about current page but you can't access the response of current page being on the page itself, what you can do is store that Token in backend and on component load fire a request to get it before and implement necessary steps!

Something that might help is Service Worker in this scenario

MiKr13
  • 1,297
  • 13
  • 20