refactor: adapt errors in apps

This commit is contained in:
Ali BARIN
2022-11-06 18:55:38 +01:00
committed by Faruk AYDIN
parent 5df7867b6d
commit ad46b3eea3
6 changed files with 80 additions and 104 deletions

View File

@@ -2,39 +2,35 @@ import { IGlobalVariable } from '@automatisch/types';
import getCurrentUser from '../common/get-current-user';
const verifyCredentials = async ($: IGlobalVariable) => {
try {
const response = await $.http.post(
`${$.app.baseUrl}/login/oauth/access_token`,
{
client_id: $.auth.data.consumerKey,
client_secret: $.auth.data.consumerSecret,
code: $.auth.data.oauthVerifier,
const response = await $.http.post(
`${$.app.baseUrl}/login/oauth/access_token`,
{
client_id: $.auth.data.consumerKey,
client_secret: $.auth.data.consumerSecret,
code: $.auth.data.oauthVerifier,
},
{
headers: {
Accept: 'application/json',
},
{
headers: {
Accept: 'application/json',
},
}
);
}
);
const data = response.data;
const data = response.data;
$.auth.data.accessToken = data.access_token;
$.auth.data.accessToken = data.access_token;
const currentUser = await getCurrentUser($);
const currentUser = await getCurrentUser($);
await $.auth.set({
consumerKey: $.auth.data.consumerKey,
consumerSecret: $.auth.data.consumerSecret,
accessToken: data.access_token,
scope: data.scope,
tokenType: data.token_type,
userId: currentUser.id,
screenName: currentUser.login,
});
} catch (error) {
throw new Error(error.response.data);
}
await $.auth.set({
consumerKey: $.auth.data.consumerKey,
consumerSecret: $.auth.data.consumerSecret,
accessToken: data.access_token,
scope: data.scope,
tokenType: data.token_type,
userId: currentUser.id,
screenName: currentUser.login,
});
};
export default verifyCredentials;