-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_console_log.js
93 lines (77 loc) · 2.31 KB
/
auth_console_log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import authAPI from '@/api/auth'
const state ={
signUpFailure:false,
showEmailCheck:'',
confirmation:false,
}
const mutations = {
registerFailure(state){
state.signUpFailure = true;
},
PASS_EMAIL_POTENTIAL_USER(state,email) {
console.log("inside mutation PASS EMAIL POT USER with email",email)
state.showEmailCheck=email;
},
SET_CONFIRM(state){
state.confirmation = true
}
}
const actions = {
register({commit},creds){
// object servResp для передачи данных в компонент
let servResp = {
status:"",
firstNameErr:[],
lastNameErr:[],
emailErr:[],
pswErr:[], //ошибки в password-e
nonFieldErr:[], // general errors (ex: email already exists...)
};
return new Promise((resolve,reject)=>{
authAPI.register(creds)
.then((resp)=>{
servResp.status = resp.status;
servResp.email = resp.data.email;
commit('PASS_EMAIL_POTENTIAL_USER',resp.data.email);
resolve (servResp)
})
.catch(err=>{
// collect all errors
servResp.status = err.response.status
servResp.firstNameErr = err.response.data.first_name;
servResp.lastNameErr = err.response.data.last_name;
servResp.emailErr = err.response.data.email;
servResp.pswErr = err.response.data.password;
servResp.nonFieldErr = err.response.data.non_field_errors;
reject(servResp)
}
)
})
},
activate({commit},creds){
// endpoint will return only: response status=204, no data
return new Promise((resolve,reject)=>{
let status = ""
authAPI.activate(creds)
.then((resp)=>{
console.log("resp in activate store is ",resp);
console.log("resp status in activate store is 204? ",resp.status);
commit('SET_CONFIRM');
console.log("msg from store: email confirmed")
status = resp.status
resolve(status)
})
.catch((err)=>{
console.log("err during email confirmation");
status = err.response.status;
commit('registerFailure')
reject(status)
})
})
}
}
export default {
state,
mutations,
actions
}