-1

So I built a program that will send an email link to people that want to register for a website and have attached a GUID at the end and stored that value in my database. I am trying to have it that when they click the link and access that page the program will parse out the GUID at the end and send it to my backend to check that it is in the database and they are allowed to view the register page.

this is an example url link that could be sent:

http://localhost:3000/#/forgotPassword?gu=7d49695a-0f33-2270-4fb9-0cb4a8b2ba9a

i can't seem to find a good way to just grab the information that is after the 'gu='.

  • Why the `#` in the URL? Why is that there? Things after the `#` will not be sent to the server. See [Why hash part is not on server](https://stackoverflow.com/questions/3664257/why-the-hash-part-of-the-url-is-not-in-the-server-side) for more info. – jfriend00 Oct 18 '17 at 18:40
  • Try `req.query.gu` – Hassan Imam Oct 18 '17 at 18:40
  • the # just generates when i run the code and use localhost to access the page – ppolicherla91 Oct 18 '17 at 18:44
  • Well, whatever is generating it is messing you up (you must be using some framework that is doing that). Things after `#` in the URL are called the fragment and they are not sent to the server so you the `gu=xxxx` value is not sent to the server. – jfriend00 Oct 18 '17 at 18:45
  • This is not a dup of an answer that just speaks about `req.query.gu`. This is a different issue because of the `#` in the URL. – jfriend00 Oct 18 '17 at 18:48

1 Answers1

0

Parts of the URL after the first # are call the fragment and are not sent to the server. This is part of a specification that explains that the fragment is retained by the user agent for its own purposes and not sent to the server.

If you want your query string sent to the server, then you need to either remove the # or place the query string before the # and then you can access the gu=xxx on your server. If you are using Express as your server framework, then you can access req.query.gu to get that value.

See Why the hash part of the URL is not in the server side? for more info about the fragment.

From your comments, it appears you are using some framework that is inserting the # in the URL (presumably some client-side framework). You will have to modify that so that the query parameter is either before the # or so that the # is not inserted into the URL at all.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • could i on the front end in angular parse the fragment string and send it back in a variable for express and node to grab? – ppolicherla91 Oct 18 '17 at 19:19
  • @ppolicherla91 - Yes, you could grab it from angular and then put it in as a regular query parameter to an ajax call that you send to your server and get back a response which your client-side Javascript could then do something with. – jfriend00 Oct 18 '17 at 19:44
  • thank you for the help!!! That pointed me in the right direction and I was able to fix the issue. – ppolicherla91 Oct 19 '17 at 03:32