mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add temp basic api login and logout methods
This commit is contained in:
parent
6fb98f2195
commit
0334515a43
1 changed files with 38 additions and 0 deletions
38
app/src/helpers/api.js
Normal file
38
app/src/helpers/api.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
|
||||
function objectToParams(object) {
|
||||
const urlParams = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
urlParams.append(key, value)
|
||||
}
|
||||
return urlParams
|
||||
}
|
||||
|
||||
|
||||
export default {
|
||||
options: {
|
||||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
headers: {
|
||||
// FIXME is it important to keep this previous `Accept` header ?
|
||||
// 'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||
// Auto header is :
|
||||
// "Accept": "*/*",
|
||||
|
||||
// Also is this still important ? (needed by back-end)
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
}
|
||||
},
|
||||
|
||||
login(password) {
|
||||
return fetch('/api/login', {
|
||||
method: 'POST',
|
||||
body: objectToParams({password}),
|
||||
...this.options
|
||||
}).then(response => (response.ok))
|
||||
},
|
||||
|
||||
logout() {
|
||||
return fetch('/api/logout', this.options).then(response => (response.ok))
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue