feat: reward
This commit is contained in:
@@ -1,33 +1,10 @@
|
||||
import axios, {AxiosHeaders, AxiosRequestConfig, AxiosRequestHeaders, InternalAxiosRequestConfig} from 'axios';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import {useDispatch} from "react-redux";
|
||||
import {logout} from "../features/auth/authSlice";
|
||||
import {store} from "../redux/store";
|
||||
import axios from 'axios';
|
||||
|
||||
export const baseUrl = 'https://assemblr.denco.store';
|
||||
// export const baseUrl = 'http://192.168.1.101:5000';
|
||||
const apiClient = axios.create({
|
||||
baseURL: baseUrl
|
||||
});
|
||||
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
const accessToken = await SecureStore.getItemAsync('accessToken');
|
||||
if (!config.headers) {
|
||||
config.headers = new AxiosHeaders();
|
||||
}
|
||||
if (accessToken) {
|
||||
config.headers.set('Authorization', `Bearer ${accessToken}`, true);
|
||||
}
|
||||
config.validateStatus = (status) => {
|
||||
if (status == 401) {
|
||||
SecureStore.deleteItemAsync('accessToken');
|
||||
store.dispatch(logout());
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return config;
|
||||
}, function (error) {
|
||||
});
|
||||
|
||||
|
||||
export default apiClient;
|
||||
|
||||
Reference in New Issue
Block a user