Search code examples
javascriptnode.jsemailgraphqlemail-verification

Link which points on a backend endpoint is displayed incorrectly in the email text


I try to include a verificaton link as plain text into an email which points on a GraphQL endpoint but browser/email client doesn't display it correctly.

It can't parse symbols like !,",{,} which I need for the link query and ultimately it becomes broken. Also, I've tried to include the link into href attribute of the a tag but the problem is, that it fails to parse double quotes also.

Link example:

https://blahblah.now.sh/graphql?query=query($email:String!,$token:String!){verifyEmailToken(email:$email,token:$token)}&variables={"email":"[email protected]","token": "221c4dfd976f3ac22f"}


Solution

  • Certain characters have special meaning in the context of a URL. You should use encodeURI to escape these characters. The resulting URL would be:

    https://blahblah.now.sh/graphql?query=query%28%24email%3AString%21%2C%24token%3AString%21%29%7BverifyEmailToken%28email%3A%24email%2Ctoken%3A%24token%29%7D%26variables%3D%7B%22email%22%3A%2222yiba%40clearmail.online%22%2C%22token%22%3A%20%22221c4dfd976f3ac22f%22%7D

    For additional details, see Why should I use urlencode? and Should I use encodeURI or encodeURIComponent for encoding URLs?