0

My project is with next.js

/auth/register
My Registration page is with a mobile number, when user enters his mobile number, the number is send to the API.

/api/v1/auth/register
At the API point, the mobile number is checked to see if it already exist or not. if not, the mobile number is stored in the MongoDB with OTP and Expiration time (2 minute).and then API send successful response as JSON to the registration page.

/auth/register/code
The second page is the OTP code verification. User must enter the received 6 digit OTP code from the SMS here. if the code is correct, the registration process will be completed successfully.

What is my problem?
So, I want entered mobile number to be send to the OTP page exactly after the API response. I do not want to use

router.push('/auth/register/code', { mobile: 1234567890 });

because I do not want to have a query in the URL. Can I send JSON to another page? Or can I use the API to send the result to the second page instead of going back to the first page?
Or what is the better way to solve my problem?

  • From the way you are wording your question, I would recommend looking into how a client/server architecture works. If you don’t have these concepts clear in your head, frameworks like Next.js will confuse things a lot. There’s many ways to do this, you can store the response in localstorage, for example, and your `code` route can read from there. – Eduardo Thales Jun 16 '22 at 20:18
  • I dont want store anywhere, like cookie or localstorage, or push with query. I can keep all operations on one page and change only jsx after each response. But I want it to be on separate pages. If I do not find a solution other than what I said, I will definitely use a cookie. – Reza Norouzzadeh Jun 16 '22 at 20:49
  • I don't understand why are you avoiding to use cookies or local storage, but if that's all you want, you can use a React `context` shared between the components that render the pages and _store_ here. "Pages" in Next.js are really just React components, you can share data with them like you would in any other. – Eduardo Thales Jun 16 '22 at 22:12
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 17 '22 at 09:55
  • Thank you so much for your guidance. you know, I was checking a site built with reactjs. No local storages or cookies is used on that site. I have no idea about useContext, maybe it will. – Reza Norouzzadeh Jun 17 '22 at 10:21
  • I want send json form API to second page. It can be possible? Without cookie and localstorage or even query. Is there a way other than this? – Reza Norouzzadeh Jun 17 '22 at 10:25
  • You can still use `router.push` and hide the query params as suggested in [How to hide query params from the URL while using router.push?](https://stackoverflow.com/questions/70484870/how-to-hide-query-params-from-the-url-while-using-router-push). – juliomalves Jun 22 '22 at 13:12

0 Answers0