benawad / type-graphql-series

Typescript GraphQL Server built with TypeGraphQL
326 stars 129 forks source link

Confirm email directly to the server #1

Open paean99 opened 5 years ago

paean99 commented 5 years ago

First thanks for this series

I just wanted to add that you can send the confirm url directly to the graphql server (http://localhost:4000/graphql). Just do a post request with an hidden form and inputs inside the email. More can be seen here: https://www.apollographql.com/docs/apollo-server/requests.html or here https://graphql.org/learn/serving-over-http/

Some attention is needed for the value of the hidden input element. The graphql query/mutation needs double quotes inside (i believe), so it would have to be wrapped inside single quotes or maybe use something like " ?

You would have to use a button which is different from a link. But the button can always be styled as a link if necessary. And also avoid using javascript. Some email providers may not like it as it can be seen as dangerous.

One much simpler alternative is to just use a get request. The advantage is that no form is needed, only a link tag. It would have to call a query (with the token as argument) and not a mutation. Although a little strange in this case (mutation seems to be the correct one), it should work.

For more practical info, one can just do several request in a graphql playground and see the request payload in the network tab of the dev tools.

edit: Forgot to add that this post was just to mention an alternative solution. But i personally think that independently of the solution, the important part is to give feedback to the user about the confirmed email.

benawad commented 5 years ago

thanks for writing this, that's a nice alternative.