add basic user authentication
This commit is contained in:
@@ -19,21 +19,43 @@ export function getBooks() {
|
||||
}
|
||||
|
||||
export function postBook(book) {
|
||||
return fetch(baseUrl + '/book', {
|
||||
return genericPostCall('/book', book.value)
|
||||
}
|
||||
|
||||
export function postLogin(user) {
|
||||
return genericPostCall('/auth/login', user.value)
|
||||
}
|
||||
|
||||
export function postSignUp(user) {
|
||||
return genericPostCall('/auth/signup', user.value)
|
||||
}
|
||||
|
||||
export function genericPostCall(apiRoute, object) {
|
||||
return fetch(baseUrl + apiRoute, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(book.value)
|
||||
body: JSON.stringify(object)
|
||||
})
|
||||
}
|
||||
|
||||
export function postSignup(user) {
|
||||
return fetch(baseUrl + '/auth/signup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(user.value)
|
||||
})
|
||||
export function extractFromErrorFromField(fieldName, errors) {
|
||||
if (errors === null || !('field' in errors)) {
|
||||
return "";
|
||||
}
|
||||
const titleErr = errs.find((e) => e["field"] === fieldName);
|
||||
if (typeof titleErr !== 'undefined') {
|
||||
return titleErr.error;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function extractGlobalFormError(errors) {
|
||||
if (errors !== null && "error" in errors) {
|
||||
return errors["error"];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user