account.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  2. import {Client} from 'sentry/api';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {User, UserIdentityConfig} from 'sentry/types';
  5. export async function disconnectIdentity(
  6. identity: UserIdentityConfig,
  7. onSuccess: {(): void}
  8. ) {
  9. const api = new Client();
  10. try {
  11. await api.requestPromise(
  12. `/users/me/user-identities/${identity.category}/${identity.id}/`,
  13. {
  14. method: 'DELETE',
  15. }
  16. );
  17. } catch {
  18. addErrorMessage('Error disconnecting identity');
  19. return;
  20. }
  21. addSuccessMessage(`Disconnected ${identity.provider.name}`);
  22. onSuccess();
  23. }
  24. export function updateUser(user: User) {
  25. const previousUser = ConfigStore.get('user');
  26. // If the user changed their theme preferences, we should also update
  27. // the config store
  28. if (
  29. previousUser.options.theme !== user.options.theme &&
  30. user.options.theme !== 'system'
  31. ) {
  32. ConfigStore.set('theme', user.options.theme);
  33. }
  34. // Ideally we'd fire an action but this is gonna get refactored soon anyway
  35. ConfigStore.set('user', user);
  36. }
  37. export function logout(api: Client) {
  38. return api.requestPromise('/auth/', {method: 'DELETE'});
  39. }
  40. export function removeAuthenticator(api: Client, userId: string, authId: string) {
  41. return api.requestPromise(`/users/${userId}/authenticators/${authId}/`, {
  42. method: 'DELETE',
  43. });
  44. }