Search code examples
restful-authenticationrestful-architecturerestful-url

should backend handle email verification request?


I am creating a web app and need to send an email verification to users after they registered in the system. When the user receives a verification email, they need to click on the link in that email to verify their email address. My question is whether the link points to my backend server or to my frontend.

Options1: If I make the link to my backend, I need to implement a GET RESTFul service to receive this request since browser couldn't send a POST request. After verification, backend will response a redirect to the browser to redirect to front end url. This may be not a best practice in terms of RESTFul design since it makes changes in my database.

Option2: If I make the link to the front end, my front end needs to parse the verify code from the url and send a post request to the backend to do the verification job.

I am not sure which one is better. Does anyone give me some suggestions on that?

My frontend and backend are separated. Backend is implemented in Python while front end is angularjs. They communicate through Restful API.


Solution

  • Your backend should handle email verification. The backend should handle all of that stuff. Assuming your URL dispatcher is in your frontend, it would get the request and then pass it to the backend.

    The common phrase is to keep all of your "business logic" in the backend. This ensures that your frontend is only focused on presenting the data.

    Your AngularJS app should handle the request, make a call to the Python backend (so it can do the logic of processing the email verification to see if it is valid or not), and then the response should come back to the AngularJS app which should format a nice looking response to the user to indicate whether the email verification worked.