|
|
@ -162,12 +162,12 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes |
|
|
|
*/ |
|
|
|
async [Action.AuthRegister]({dispatch}, payload: IRegisterPayload) { |
|
|
|
try { |
|
|
|
let [status, body] = await dispatch(Action.Post, { |
|
|
|
let [status, response] = await dispatch(Action.Post, { |
|
|
|
path: `/auth/register`, |
|
|
|
useAuth: false, |
|
|
|
body: payload}); |
|
|
|
if (status !== 200) { |
|
|
|
return body.errors ?? {}; |
|
|
|
return response.errors ?? {}; |
|
|
|
} |
|
|
|
} catch(e) { |
|
|
|
console.error("Error occurred during registration", e); |
|
|
@ -181,17 +181,18 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes |
|
|
|
*/ |
|
|
|
async [Action.AuthLogin]({commit, dispatch}, {email, password, remember = false}) { |
|
|
|
try { |
|
|
|
let [status, body] = await dispatch(Action.Post, { |
|
|
|
let [status, response] = await dispatch(Action.Post, { |
|
|
|
path: `/auth/login?use_cookies=${navigator.cookieEnabled}`, |
|
|
|
useAuth: false, |
|
|
|
body: {email, password}}); |
|
|
|
if (status !== 200) { |
|
|
|
if (status === 401) { |
|
|
|
body.errors = { "email": ["Email or password is incorrect"] }; |
|
|
|
response.errors = { "email": ["Email or password is incorrect"] }; |
|
|
|
} |
|
|
|
return body.errors || {}; |
|
|
|
return response.errors || {}; |
|
|
|
} |
|
|
|
commit(Mutation.UserLoad, body.token); |
|
|
|
console.log(response); |
|
|
|
commit(Mutation.UserLoad, response.result.token); |
|
|
|
commit(Mutation.UserStore, remember); |
|
|
|
} catch(e) { |
|
|
|
console.error("Error occurred during login:", e); |
|
|
|