API & Client - user can delete his account - fix #17

This commit is contained in:
Sam
2020-05-01 16:18:59 +02:00
parent 3d01eadc71
commit f249b09146
14 changed files with 365 additions and 9 deletions

View File

@ -2,7 +2,7 @@ import FitTrackeeGenericApi from '../fitTrackeeApi'
import FitTrackeeApi from '../fitTrackeeApi/auth'
import { history } from '../index'
import { generateIds } from '../utils'
import { getOrUpdateData, updateLanguage } from './index'
import { getOrUpdateData, setError, updateLanguage } from './index'
const AuthError = message => ({ type: 'AUTH_ERROR', message })
@ -133,3 +133,15 @@ export const deletePicture = () => dispatch =>
.catch(error => {
throw error
})
export const deleteUser = username => dispatch =>
FitTrackeeGenericApi.deleteData('users', username)
.then(ret => {
if (ret.status === 204) {
dispatch(logout())
history.push('/')
} else {
ret.json().then(r => dispatch(setError(`${r.message}`)))
}
})
.catch(error => dispatch(setError(`user|${error}`)))