swagger-to-react-query
v0.1.9
Published
## Try
Downloads
4
Maintainers
Readme
swagger-to-react-query WIP
Try
$ git clone https://github.com/elsangedy/swagger-to-react-query.git
$ cd swagger-to-react-query/examples
$ node ../src/index config.js
$ // or
$ npx swagger-to-react-query config.js
const addToken = (request) => {
const token = authService.getToken()
if (token) {
request.headers.set('authorization', `Bearer ${token}`)
}
}
const refreshToken = async ({ request }) => {
try {
await authService.refreshToken()
addToken(request)
} catch (e) {
authService.logout()
}
}
// https://github.com/sindresorhus/ky
extendApi({
prefixUrl: API_URL,
hooks: {
beforeRequest: [addToken],
beforeRetry: [refreshToken],
},
})