Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. onSubmit () {
  2. const formData = {
  3. email: this.email,
  4. age: this.age,
  5. password: this.password,
  6. confirmPassword: this.confirmPassword,
  7. country: this.country,
  8. hobbies: this.hobbyInputs.map(hobby => hobby.value),
  9. terms: this.terms
  10. }
  11. this.$store.dispatch('signup', formData)
  12. }
  13.  
  14. signup({commit, dispatch}, authData){
  15. axios.post('/signupNewUser?key=theapikey', {
  16. email: authData.email,
  17. password: authData.password,
  18. returnSecureToken: true
  19. })
  20. .then(res => {
  21. console.log(res)
  22. commit('authUser', {
  23. token: res.data.idToken,
  24. userId: res.data.localId
  25. })
  26. dispatch('storeUser', authData)
  27. })
  28. .catch(error => console.log(error))
  29. },
  30.  
  31. storeUser({commit, state}, userData){
  32. if(!state.idToken){
  33. return
  34. }
  35. globalaxios.post('/users.json' + '?auth=' + state.idToken, userData)
  36. .then(res => console.log(res))
  37. .catch(error => console.log(error))
  38. },
  39.  
  40. mutations: {
  41. authUser (state, userData){
  42. state.idToken = userData.idToken
  43. state.userId = userData.userId
  44. },
  45. storeUser(state, user){
  46. state.user = user
  47. }
  48.  
  49. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement