Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

[$40] Resume link support token with redirect #492

Closed
maxceem opened this issue Aug 18, 2021 · 4 comments
Closed

[$40] Resume link support token with redirect #492

maxceem opened this issue Aug 18, 2021 · 4 comments

Comments

@maxceem
Copy link
Contributor

maxceem commented Aug 18, 2021

background

We have a page where we are showing Job Candidate resume link https://platform.topcoder-dev.com/taas/myteams/18361/positions/684d1d9b-32b5-4e0c-bb2c-e031db694c75/candidates/to-review

image

This is some third-party link, when we click it, the download is started.

Though we need to track when user downloads this resume. For this purpose we implemented a special endpoint ${config.API.V5}/jobCandidates/{jobCandidateId}/resume which should be called using user token as all other endpoints. This endpoint would internally track this call and redirect to the real third-party resume URL.

We cannot just replace URL in this link to the ${config.API.V5}/jobCandidates/{jobCandidateId}/resume because we also have to pass JWT token in the header.

Task

We have to update this link so it works like this:

  • it should not be a real link so user cannot copy it or open it in a new window
  • it should still look like a link, and when we click it it should internally call endpoint ${config.API.V5}/jobCandidates/{jobCandidateId}/resume get the URL where this endpoint redirected and open that URL in a new window.
  • NOTE: that this link should be only visible if resume is not null as it's done now
  • axios looks like support disabling redirects Fixing #211 axios/axios#307, so the logic could be like this:
    • using axios get URL ${config.API.V5}/jobCandidates/{jobCandidateId}/resume
    • disalbe redirects to avoid downloading of actual resume
    • get the URL where it was redirected to and open in a new tab/window
@maxceem
Copy link
Contributor Author

maxceem commented Aug 19, 2021

Current approach appeared to have some drawbacks, so we have to find a better to handle it in general and implement it a different way in the API too.

browsers always follow redirects (redirects from XHR/fetch requests cannot be prevented). Axios' "maxRedirects" option works only in Node.js. From axios docs:
maxRedirects defines the maximum number of redirects to follow in node.js
As a result the endpoint "/jobCandidates/{jobCandidateId}/resume" seems to be unusable since it both requires a token that must be set in JS (which prevents the use of this endpoint in anchor elements) and does the redirect (which will most probably cause CORS error at the very least).
I ended up creating a PR anyway. #493

@maxceem
Copy link
Contributor Author

maxceem commented Aug 19, 2021

@maxceem
Copy link
Contributor Author

maxceem commented Aug 20, 2021

For now I've merged the current implementation, but we will try come up with a better solution during cool down period. Will track it via #495

@sdgun
Copy link

sdgun commented Aug 23, 2021

Verified resume downloading in dev and prod.

@sdgun sdgun closed this as completed Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants