1
0
Fork 0
freesewing/sites/shared/backend.mjs

28 lines
620 B
JavaScript
Raw Normal View History

2022-12-27 18:20:53 +01:00
import axios from 'axios'
2023-01-09 21:37:05 +01:00
import process from 'process'
2022-12-27 18:20:53 +01:00
/*
* Helper methods to interact with the FreeSewing backend
*/
const backend = axios.create({
baseURL: process.env.NEXT_PUBLIC_BACKEND || 'https://backend.freesewing.org',
timeout: 3000,
})
2023-01-14 17:08:33 +01:00
/*
* User signup
*/
2022-12-27 18:20:53 +01:00
export const signUp = async ({ email, language, startLoading, stopLoading }) => {
let result
try {
startLoading()
result = await backend.post('/signup', { email, language })
} catch (err) {
2023-01-14 17:31:55 +01:00
return err
2022-12-27 18:20:53 +01:00
} finally {
stopLoading()
}
2023-01-14 17:31:55 +01:00
if (result && result.status === 201 && result.data) return result.data
return null
2022-12-27 18:20:53 +01:00
}