pleroma/app/soapbox/actions/apps.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-08-21 17:05:59 -07:00
import { baseClient } from '../api';
export const APP_CREATE_REQUEST = 'APP_CREATE_REQUEST';
export const APP_CREATE_SUCCESS = 'APP_CREATE_SUCCESS';
export const APP_CREATE_FAIL = 'APP_CREATE_FAIL';
export const APP_VERIFY_CREDENTIALS_REQUEST = 'APP_VERIFY_CREDENTIALS_REQUEST';
export const APP_VERIFY_CREDENTIALS_SUCCESS = 'APP_VERIFY_CREDENTIALS_SUCCESS';
export const APP_VERIFY_CREDENTIALS_FAIL = 'APP_VERIFY_CREDENTIALS_FAIL';
export function createApp(params) {
return (dispatch, getState) => {
dispatch({ type: APP_CREATE_REQUEST, params });
return baseClient().post('/api/v1/apps', params).then(({ data: app }) => {
dispatch({ type: APP_CREATE_SUCCESS, params, app });
return app;
}).catch(error => {
dispatch({ type: APP_CREATE_FAIL, params, error });
throw error;
});
};
}
export function verifyAppCredentials(token) {
return (dispatch, getState) => {
dispatch({ type: APP_VERIFY_CREDENTIALS_REQUEST, token });
return baseClient(token).get('/api/v1/apps/verify_credentials').then(({ data: app }) => {
dispatch({ type: APP_VERIFY_CREDENTIALS_SUCCESS, token, app });
return app;
}).catch(error => {
dispatch({ type: APP_VERIFY_CREDENTIALS_FAIL, token, error });
throw error;
});
};
}