Skip to content
Advertisement

How can I get token from the URL in Nextjs / React App?

I am working on an API based project.

I have my front-end interface with React and Next.js and the API back-end builds with Laravel.

I have a front-end page with a token in URL which I have made in my Laravel back-end to identify the user.

Question:

How can I get the token from URL in client-side for sending it back to my back-end in a post request to compare and verify the user then insert it in my database?

Advertisement

Answer

You can retrieve it using props, (ignore this. if you use a function component as YourPage)

this.props.match.params.token

You also need to have a route definition like this

<Route exact path="/add-account/:token" component={YourPage}/>
Advertisement