feat: change email, export my data, delete account (with data anonymization)
This commit is contained in:
1 parent
bb191c389a
commit
10a66cd979
123 files changed
+10789
-76
No files matched your search
@@ -3,7 +3,7 @@ import { useApi } from '@/composables/useApi'
|
||||
const JSON_HEADERS = { 'Content-Type': 'application/json' }
|
||||
|
||||
export function useProfile() {
|
||||
const { request } = useApi()
|
||||
const { request, requestFile } = useApi()
|
||||
|
||||
function updateDisplayName(displayName: string) {
|
||||
return request<{ display_name?: string | null }>('/v1/user/me', {
|
||||
@@ -21,5 +21,53 @@ export function useProfile() {
|
||||
})
|
||||
}
|
||||
|
||||
return { updateDisplayName, sendPasswordReset }
|
||||
function requestEmailChange(newEmail: string, currentPassword: string) {
|
||||
return request<{ pending_email: string }>('/v1/auth/email/change', {
|
||||
method: 'POST',
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify({ new_email: newEmail, current_password: currentPassword }),
|
||||
})
|
||||
}
|
||||
|
||||
function resendEmailChange() {
|
||||
return request<{ pending_email: string }>('/v1/auth/email/resend', { method: 'POST' })
|
||||
}
|
||||
|
||||
function cancelEmailChange() {
|
||||
return request<void>('/v1/auth/email/change', { method: 'DELETE' })
|
||||
}
|
||||
|
||||
function confirmEmailChange(code: string) {
|
||||
return request<{ email: string }>('/v1/auth/email/confirm', {
|
||||
method: 'POST',
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify({ code }),
|
||||
onUnauthorized: 'passthrough',
|
||||
onForbidden: 'passthrough',
|
||||
})
|
||||
}
|
||||
|
||||
function downloadMyData() {
|
||||
return requestFile('/v1/user/me/export')
|
||||
}
|
||||
|
||||
function deleteAccount(currentPassword: string, confirmation: string) {
|
||||
return request<void>('/v1/user/me', {
|
||||
method: 'DELETE',
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify({ current_password: currentPassword, confirmation }),
|
||||
onUnauthorized: 'passthrough',
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
deleteAccount,
|
||||
downloadMyData,
|
||||
updateDisplayName,
|
||||
sendPasswordReset,
|
||||
requestEmailChange,
|
||||
resendEmailChange,
|
||||
cancelEmailChange,
|
||||
confirmEmailChange,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user