mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-12 12:31:06 +03:30
Saeid74
This commit is contained in:
+3
-1
@@ -1,6 +1,7 @@
|
||||
import { ApiService } from "../global/api.service";
|
||||
import { TokenService } from "./storage.service";
|
||||
import { urls } from "@/config/urls";
|
||||
import toast from "../global/toast.service";
|
||||
|
||||
class AuthenticationError extends Error {
|
||||
constructor(errorCode, message) {
|
||||
@@ -42,8 +43,9 @@ const UserService = {
|
||||
// NOTE: We haven't covered this yet in our ApiService
|
||||
// but don't worry about this just yet - I'll come back to it later
|
||||
ApiService.mount401Interceptor();
|
||||
return response.data.access_token;
|
||||
return response;
|
||||
} catch (error) {
|
||||
toast.error('Username Or Password Is Incorrect', 'Error');
|
||||
throw new AuthenticationError(
|
||||
error.response.status,
|
||||
error.response.data.detail
|
||||
|
||||
+3
-3
@@ -6,14 +6,14 @@ export default {
|
||||
async login({ commit, dispatch }, {cell_number, password}) {
|
||||
commit('loginRequest');
|
||||
try {
|
||||
const token = await UserService.login(cell_number, password);
|
||||
commit('loginSuccess', token);
|
||||
const response = await UserService.login(cell_number, password);
|
||||
commit('loginSuccess', response.data.access_token);
|
||||
// Redirect the user to the page he first tried to visit or to the home view
|
||||
router.push(router.history.current.query.redirect || '/');
|
||||
|
||||
dispatch('info', {}, {root : true});
|
||||
|
||||
return true
|
||||
return response;
|
||||
} catch (e) {
|
||||
if (e instanceof AuthenticationError) {
|
||||
commit('loginError', {errorCode: e.errorCode, errorMessage: e.message})
|
||||
|
||||
@@ -80,11 +80,14 @@ export default {
|
||||
...mapActions('auth', [
|
||||
'login'
|
||||
]),
|
||||
handleSubmit() {
|
||||
async handleSubmit() {
|
||||
// Perform a simple validation that cell_number and password have been typed in
|
||||
if (this.$refs.form.validate()) {
|
||||
this.login({cell_number: this.cell_number, password: this.password});
|
||||
this.password = "";
|
||||
const response = await this.login({cell_number: this.cell_number, password: this.password});
|
||||
|
||||
if (!response.status || response.status !== 200) {
|
||||
this.password = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user