Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onSubmit () {
- const formData = {
- email: this.email,
- age: this.age,
- password: this.password,
- confirmPassword: this.confirmPassword,
- country: this.country,
- hobbies: this.hobbyInputs.map(hobby => hobby.value),
- terms: this.terms
- }
- this.$store.dispatch('signup', formData)
- }
- signup({commit, dispatch}, authData){
- axios.post('/signupNewUser?key=theapikey', {
- email: authData.email,
- password: authData.password,
- returnSecureToken: true
- })
- .then(res => {
- console.log(res)
- commit('authUser', {
- token: res.data.idToken,
- userId: res.data.localId
- })
- dispatch('storeUser', authData)
- })
- .catch(error => console.log(error))
- },
- storeUser({commit, state}, userData){
- if(!state.idToken){
- return
- }
- globalaxios.post('/users.json' + '?auth=' + state.idToken, userData)
- .then(res => console.log(res))
- .catch(error => console.log(error))
- },
- mutations: {
- authUser (state, userData){
- state.idToken = userData.idToken
- state.userId = userData.userId
- },
- storeUser(state, user){
- state.user = user
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement