This library makes it easy.
const auth = new EasyAuth('https://jsonplaceholder.typicode.com', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9')
First we need to create the EasyAuth class. Parameters accept site url, access token.
const postData = async () => {
const responce = await auth.post('/posts', {}, {Header: 'value'})
console.log('POST')
console.log(responce.data)
}
// post(path: string, body: array, headers: array)
Then you can make requests to the server.
EasyAuth supports GET, POST, PUT, PATCH, DELETE methods.
You need axios to work.
Documentation for all methods on github. Please write about errors there.
Пример: https://github.com/KirillUsenko/examples-axios-easy-auth
Были проблемы с добавлением хэдеров в запрос?
Данная библиотека упрощает это.
const auth = new EasyAuth('https://jsonplaceholder.typicode.com', 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9')
Для начала нужно создать класс EasyAuth. Параметрами принимает url сайта, access токен.
const postData = async () => {
const responce = await auth.post('/posts', {}, {Header: 'value'})
// post(path: string, body: array, headers: array)
console.log('POST')
console.log(responce.data)
}
Далее можно делать запросы на сервер.
EasyAuth поддерживает методы GET, POST, PUT, PATCH, DELETE.
Для работы нужен axios.
Документация для всех методов на github. Про ошибки пишите туда же.
Пример: https://github.com/KirillUsenko/examples-axios-easy-auth