NickMarinade / lightz

0 stars 4 forks source link

Problem getting the token from the URL on the front end #8

Closed AlejoVE closed 4 years ago

AlejoVE commented 4 years ago

We need help getting a token from URL in React.

We need to take the token as a parameter from the URL, but we don't know how to do it in the fron-end.

We are working with react-router.

Thi is what users see in the search bar on their browser: http://localhost:3000/reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZjI0ODRkZTI5OGNhYTA1YTQwYzAzMTEiLCJpYXQiOjE1OTYyODk2MzcsImV4cCI6MTU5NjI5MDgzN30.bqNDnB63TV7YJMJjOi9B1KqbwA5HsuJ8LSKFoltOdok

This is the request that we have to send to the back-end:

await Axios.put('http://localhost:8080/api/reset-password/${token}'

How can we take that token from the URL?.

Our code https://github.com/NickMarinade/lightz/blob/updates/src/Front/components/password/NewPassword.js

maeligg commented 4 years ago

Hi,

I don't think you need to use react-router for this, you should be able to do something like this :

const currentURL = window.location
const parts = myURL.split('reset-password/')
const token = parts[1]