mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 10:31:06 +03:30
send Api Ok
This commit is contained in:
+11
-5
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import { TokenService } from './storage.service'
|
||||
import store from '@/store'
|
||||
import qs from 'qs';
|
||||
|
||||
const ApiService = {
|
||||
|
||||
@@ -44,7 +45,12 @@ const ApiService = {
|
||||
* - password
|
||||
**/
|
||||
customRequest(data) {
|
||||
return axios(data)
|
||||
for (let d in data) {
|
||||
if (typeof data[d] == 'object') {
|
||||
data[d] = qs.stringify(data[d]);
|
||||
}
|
||||
}
|
||||
return axios(data);
|
||||
},
|
||||
|
||||
_401interceptor: null,
|
||||
@@ -56,10 +62,10 @@ const ApiService = {
|
||||
},
|
||||
async (error) => {
|
||||
if (error.request.status == 401) {
|
||||
if (error.config.url.includes('/auth/login/')) {
|
||||
if (error.config.url.includes('auth/login')) {
|
||||
// Refresh token has failed. Logout the user
|
||||
store.dispatch('auth/logout')
|
||||
throw error
|
||||
store.dispatch('auth/logout');
|
||||
throw error;
|
||||
} else {
|
||||
// Refresh the access token
|
||||
try{
|
||||
@@ -90,4 +96,4 @@ const ApiService = {
|
||||
}
|
||||
|
||||
export default ApiService
|
||||
export { ApiService}
|
||||
export { ApiService }
|
||||
|
||||
+31
-3
@@ -21,7 +21,7 @@ const UserService = {
|
||||
login: async function(cell_number, password) {
|
||||
const requestData = {
|
||||
method: 'post',
|
||||
url: "login",
|
||||
url: "/login",
|
||||
data: {
|
||||
cell_number,
|
||||
password,
|
||||
@@ -57,7 +57,7 @@ const UserService = {
|
||||
forgotPassword: async function(cell_number) {
|
||||
const requestData = {
|
||||
method: 'post',
|
||||
url: "/forgotPassword",
|
||||
url: "forgotPassword",
|
||||
data: {
|
||||
cell_number,
|
||||
},
|
||||
@@ -70,7 +70,35 @@ const UserService = {
|
||||
try {
|
||||
const response = await ApiService.customRequest(requestData);
|
||||
ApiService.setHeader();
|
||||
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw new AuthenticationError(error.response.status, error.response.data.detail);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Login the user and store the access token to TokenService.
|
||||
*
|
||||
* @returns access_token
|
||||
* @throws AuthenticationError
|
||||
**/
|
||||
verifyCode: async function(verifyCode) {
|
||||
const requestData = {
|
||||
method: 'post',
|
||||
url: "forgotPassword",
|
||||
data: {
|
||||
verifyCode,
|
||||
},
|
||||
auth: {
|
||||
username: process.env.VUE_APP_CLIENT_ID,
|
||||
password: process.env.VUE_APP_CLIENT_SECRET
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await ApiService.customRequest(requestData);
|
||||
ApiService.setHeader();
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw new AuthenticationError(error.response.status, error.response.data.detail);
|
||||
|
||||
Reference in New Issue
Block a user