| 1 |
import { Axios as api } from './axios' |
| 2 |
|
| 3 |
export const User = { |
| 4 |
async getData() { |
| 5 |
// Zustand changed their persist middleware to bind to the store |
| 6 |
// so api was undefined here. That's why using fetch for this one request. |
| 7 |
const data = await fetch(`${window.extendifyData.root}/user`, { |
| 8 |
method: 'GET', |
| 9 |
headers: { |
| 10 |
'X-WP-Nonce': window.extendifyData.nonce, |
| 11 |
'X-Requested-With': 'XMLHttpRequest', |
| 12 |
'X-Extendify': true, |
| 13 |
}, |
| 14 |
}) |
| 15 |
return await data.json() |
| 16 |
}, |
| 17 |
getMeta(key) { |
| 18 |
return api.get('user-meta', { |
| 19 |
params: { |
| 20 |
key, |
| 21 |
}, |
| 22 |
}) |
| 23 |
}, |
| 24 |
authenticate(email, key) { |
| 25 |
const formData = new FormData() |
| 26 |
formData.append('email', email) |
| 27 |
formData.append('key', key) |
| 28 |
return api.post('login', formData, { |
| 29 |
headers: { |
| 30 |
'Content-Type': 'multipart/form-data', |
| 31 |
}, |
| 32 |
}) |
| 33 |
}, |
| 34 |
register(email) { |
| 35 |
const formData = new FormData() |
| 36 |
formData.append('data', email) |
| 37 |
return api.post('register', formData, { |
| 38 |
headers: { |
| 39 |
'Content-Type': 'multipart/form-data', |
| 40 |
}, |
| 41 |
}) |
| 42 |
}, |
| 43 |
setData(data) { |
| 44 |
const formData = new FormData() |
| 45 |
formData.append('data', JSON.stringify(data)) |
| 46 |
return api.post('user', formData, { |
| 47 |
headers: { |
| 48 |
'Content-Type': 'multipart/form-data', |
| 49 |
}, |
| 50 |
}) |
| 51 |
}, |
| 52 |
deleteData() { |
| 53 |
return api.post('clear-user') |
| 54 |
}, |
| 55 |
registerMailingList(email) { |
| 56 |
const formData = new FormData() |
| 57 |
formData.append('email', email) |
| 58 |
return api.post('register-mailing-list', formData, { |
| 59 |
headers: { |
| 60 |
'Content-Type': 'multipart/form-data', |
| 61 |
}, |
| 62 |
}) |
| 63 |
}, |
| 64 |
allowedImports() { |
| 65 |
return api.get('max-free-imports') |
| 66 |
}, |
| 67 |
} |
| 68 |
|