80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { AxiosInstance } from 'axios';
|
|
import Header from '../_APITool/Header';
|
|
import {
|
|
UserAPIProps,
|
|
PostUserRefreshAPIPromise,
|
|
GetUserSingleSignInAPIPromise,
|
|
GetUserAccountInfoAPIPromise,
|
|
PostUserSignOutAPIPromise,
|
|
} from './types';
|
|
|
|
export function CreatUserAPI({ axios, header }: { axios: AxiosInstance; header: Header }): UserAPIProps {
|
|
return {
|
|
getUserSSO: async (backUrl: string): Promise<GetUserSingleSignInAPIPromise> => {
|
|
try {
|
|
const res = await axios.get('/account/login/sso', {
|
|
params: {
|
|
back_url: backUrl,
|
|
},
|
|
});
|
|
return res.data;
|
|
} catch (error) {
|
|
const errorMessage = {
|
|
url: '',
|
|
error: error.response?.data,
|
|
} as GetUserSingleSignInAPIPromise;
|
|
return errorMessage;
|
|
}
|
|
},
|
|
postUserRefreshToken: async (): Promise<PostUserRefreshAPIPromise> => {
|
|
try {
|
|
const res = await axios.post('/account/refresh_token', undefined, {
|
|
headers: { ...header.header },
|
|
});
|
|
return res.data;
|
|
} catch (error) {
|
|
const errorMessage = {
|
|
token: '',
|
|
error: error.response?.data,
|
|
};
|
|
return errorMessage;
|
|
}
|
|
},
|
|
getUserAccountInfo: async (): Promise<GetUserAccountInfoAPIPromise> => {
|
|
try {
|
|
const res = await axios.get('/account', {
|
|
headers: { ...header.header },
|
|
});
|
|
return res.data;
|
|
} catch (error) {
|
|
const errorMessage = {
|
|
account: {
|
|
_id: '',
|
|
username: '',
|
|
email: '',
|
|
display_name: '',
|
|
createdAt: '',
|
|
updatedAt: '',
|
|
error: error.response?.data,
|
|
},
|
|
};
|
|
return errorMessage;
|
|
}
|
|
},
|
|
postUserSignOut: async (): Promise<PostUserSignOutAPIPromise> => {
|
|
try {
|
|
const res = await axios.post('/account/logout', undefined, {
|
|
headers: { ...header.header },
|
|
});
|
|
return res.data;
|
|
} catch (error) {
|
|
const errorMessage = {
|
|
url: '',
|
|
error: error.response?.data,
|
|
};
|
|
return errorMessage;
|
|
}
|
|
},
|
|
};
|
|
}
|