[Vuejs]-Vue.js | TypeError: Cannot read property 'then' of undefined

2👍

You forgot to return the response from DataService.registerUser

// DataService.js
registerUser(user) {
 // Send email for registration
 return apiClient.post('/user/register/sendMail', user)
   .then(res => {
     return apiClient.post(`/user/register`, user)
   })
   .catch(err => {
     throw err;
   })
👤Naren

2👍

The issue is that your registerUser function doesn’t return anything whereas you’re expecting it to return a promise.

Change your registerUser to:

registerUser(user) {
  // Send email for registration
  return apiClient.post('/user/register/sendMail', user)
   .then(res => {
     return apiClient.post(`/user/register`, user)
   })
}

(FYI in the example, I left the .throw out because it already gets handled by the Promise you return 😉

👤Ian

Leave a comment