fixed bug auth in useRequest
This commit is contained in:
@@ -6,6 +6,7 @@ import useUser from "@/lib/app/hooks/useUser";
|
||||
import {errorRequest, errorResponse, errorSetting} from "@/core/utils/errorHandler";
|
||||
|
||||
const defaultOptions = {
|
||||
auth: false,
|
||||
data: {},
|
||||
requestOptions: {
|
||||
headers: {}
|
||||
@@ -28,12 +29,16 @@ const useRequest = (initOptions) => {
|
||||
const {token, clearToken} = useUser()
|
||||
let _options = {...defaultOptions, ...initOptions}
|
||||
|
||||
function requestServer(url = '', method = 'get', auth = false, options) {
|
||||
function requestServer(url = '', method = 'get', options) {
|
||||
_options = {..._options, ...options}
|
||||
if (auth) _options = {
|
||||
if (_options.auth) _options = {
|
||||
..._options,
|
||||
requestOptions: {..._options.requestOptions.headers, authorization: `Bearer ${token}`}
|
||||
requestOptions: {
|
||||
..._options.requestOptions,
|
||||
headers: {..._options.requestOptions.headers, authorization: `Bearer ${token}`}
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (_options.notification && _options.failed.notification.show && _options.pending) PendingNotification(t)
|
||||
axios({
|
||||
|
||||
Reference in New Issue
Block a user