🐛 Fixed issue in utils/backend
This commit is contained in:
parent
7ebc512142
commit
cd11ea96fa
2 changed files with 54 additions and 39 deletions
8
.circleci/config.yml
Normal file
8
.circleci/config.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: circleci/node:lts
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: npm install --global lerna && lerna bootstrap
|
|
@ -1,61 +1,68 @@
|
||||||
import axios from 'axios'
|
import axios from "axios";
|
||||||
|
|
||||||
function useBackend(baseURL, timeout = 10000) {
|
function useBackend(baseURL, timeout = 10000) {
|
||||||
// Configure Axios
|
// Configure Axios
|
||||||
const api = axios.create({ baseURL, timeout })
|
const api = axios.create({ baseURL, timeout });
|
||||||
|
|
||||||
// Helper method for Authorization header
|
// Helper method for Authorization header
|
||||||
const auth = token => ({
|
const auth = token => ({
|
||||||
headers: { Authorization: 'Bearer ' + token }
|
headers: { Authorization: "Bearer " + token }
|
||||||
})
|
});
|
||||||
|
|
||||||
const backend = {}
|
const backend = {};
|
||||||
|
|
||||||
// Oauth
|
// Oauth
|
||||||
backend.initOauth = data => api.post('/oauth/init', data) // Init Oauth (to get state)
|
backend.initOauth = data => api.post("/oauth/init", data); // Init Oauth (to get state)
|
||||||
backend.providerLogin = data => api.post('/oauth/login', data) // Finalize Oauth login
|
backend.providerLogin = data => api.post("/oauth/login", data); // Finalize Oauth login
|
||||||
|
|
||||||
// Signup flow
|
// Signup flow
|
||||||
backend.signup = (email, password, language) => api.post('/signup', { email, password, language }) // Signup
|
backend.signup = (email, password, language) =>
|
||||||
backend.confirm = confirmId => api.post('/account', { id: confirmId }) // Confirm
|
api.post("/signup", { email, password, language }); // Signup
|
||||||
backend.createAccount = (confirmId, consent) => api.post('/account', { id: confirmId, consent }) // Create account
|
backend.confirm = confirmId => api.post("/account", { id: confirmId }); // Confirm
|
||||||
|
backend.createAccount = (confirmId, consent) =>
|
||||||
|
api.post("/account", { id: confirmId, consent }); // Create account
|
||||||
|
|
||||||
// Other non-authenticated calls
|
// Other non-authenticated calls
|
||||||
backend.login = (username, password) => api.post('/login', { username, password }) // Login
|
backend.login = (username, password) =>
|
||||||
backend.confirmationLogin = id => api.post('/confirm/login', { id }) // Confirmation-based login
|
api.post("/login", { username, password }); // Login
|
||||||
backend.resetPassword = username => api.post('/reset/password', { username: username }) // Ask for a password reset
|
backend.confirmationLogin = id => api.post("/confirm/login", { id }); // Confirmation-based login
|
||||||
backend.loadGist = handle => api.get('/gist/' + handle) // Load recipe/gist anonymously
|
backend.resetPassword = username =>
|
||||||
backend.loadPatrons = handle => api.get('/patrons') // Load patron list
|
api.post("/reset/password", { username: username }); // Ask for a password reset
|
||||||
|
backend.loadGist = handle => api.get("/gist/" + handle); // Load recipe/gist anonymously
|
||||||
|
backend.loadPatrons = handle => api.get("/patrons"); // Load patron list
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
backend.profile = (username, token) => api.get('/users/' + username, auth(token)) // Load user profile
|
backend.profile = (username, token) =>
|
||||||
backend.account = token => api.get('/account', auth(token)) // Try to authenticate based on stored token
|
api.get("/users/" + username, auth(token)); // Load user profile
|
||||||
backend.export = token => api.get('/export', auth(token)) // Export data
|
backend.account = token => api.get("/account", auth(token)); // Try to authenticate based on stored token
|
||||||
backend.restrict = token => api.get('/restrict', auth(token)) // Restrict data processing (freeze account)
|
backend.export = token => api.get("/export", auth(token)); // Export data
|
||||||
backend.remove = token => api.get('/remove', auth(token)) // Remove account
|
backend.restrict = token => api.get("/restrict", auth(token)); // Restrict data processing (freeze account)
|
||||||
backend.saveAccount = (data, token) => api.put('/account', data, auth(token)) // Update account
|
backend.remove = token => api.get("/remove", auth(token)); // Remove account
|
||||||
backend.availableUsername = (data, token) => api.post('/available/username', data, auth(token)) // Check is a username is available
|
backend.saveAccount = (data, token) => api.put("/account", data, auth(token)); // Update account
|
||||||
backend.setPassword = (data, token) => api.post('/set/password', data, auth(token)) // (re)set a new password
|
backend.availableUsername = (data, token) =>
|
||||||
|
api.post("/available/username", data, auth(token)); // Check is a username is available
|
||||||
|
backend.setPassword = (data, token) =>
|
||||||
|
api.post("/set/password", data, auth(token)); // (re)set a new password
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
backend.createModel = (data, token) => api.post('/model', data, auth(token)) // Create model
|
backend.createModel = (data, token) => api.post("/models", data, auth(token)); // Create model
|
||||||
backend.saveModel = (handle, data, token) => api.put('/model/' + handle, data, auth(token)) // Update model
|
backend.saveModel = (handle, data, token) =>
|
||||||
backend.removeModel = (handle, token) => api.delete('/model/' + handle, auth(token)) // Remove model
|
api.put("/models/" + handle, data, auth(token)); // Update model
|
||||||
backend.removeModels = (data, token) => api.post('/remove/models', data, auth(token)) // Delete multiple models
|
backend.removeModel = (handle, token) =>
|
||||||
|
api.delete("/models/" + handle, auth(token)); // Remove model
|
||||||
|
//backend.removeModels = (data, token) => api.post('/remove/models', data, auth(token)) // Delete multiple models
|
||||||
|
|
||||||
// Recipes
|
// Recipes
|
||||||
backend.loadRecipe = (handle, token) => api.get('/recipe/' + handle, auth(token)) // Load recipe
|
backend.loadRecipe = (handle, token) =>
|
||||||
backend.createRecipe = (data, token) => api.post('/recipe', data, auth(token)) // Create recipe
|
api.get("/recipes/" + handle, auth(token)); // Load recipe
|
||||||
backend.removeRecipe = (handle, token) => api.delete('/recipe/' + handle, auth(token)) // Remove recipe
|
backend.createRecipe = (data, token) =>
|
||||||
backend.saveRecipe = (handle, data, token) => api.put('/recipe/' + handle, data, auth(token)) // Update recipe
|
api.post("/recipes", data, auth(token)); // Create recipe
|
||||||
|
backend.removeRecipe = (handle, token) =>
|
||||||
|
api.delete("/recipes/" + handle, auth(token)); // Remove recipe
|
||||||
|
backend.saveRecipe = (handle, data, token) =>
|
||||||
|
api.put("/recipes/" + handle, data, auth(token)); // Update recipe
|
||||||
|
|
||||||
//backend.createDraft = (data, token) => api.post("/draft", data, auth(token)); // Create draft
|
return backend;
|
||||||
//backend.saveDraft = (handle, data, token) =>
|
|
||||||
// api.put("/draft/" + handle, data, auth(token)); // Update draft
|
|
||||||
//backend.removeDrafts = (data, token) =>
|
|
||||||
// api.post("/remove/drafts", data, auth(token)); // Delete multiple drafts
|
|
||||||
|
|
||||||
return backend
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useBackend
|
export default useBackend;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue