profile not done
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import * as Keychain from "react-native-keychain";
|
||||
|
||||
/**
|
||||
* Generic API call function with proper error handling and optional auth.
|
||||
* @param url - API endpoint
|
||||
* @param method - HTTP method: GET, POST, PUT, DELETE
|
||||
* @param data - Request body for POST/PUT
|
||||
* @param config - Optional Axios config (headers, params, etc.)
|
||||
*/
|
||||
export async function apiCall<T>(
|
||||
url: string,
|
||||
method: "GET" | "POST" | "PUT" | "DELETE" = "GET",
|
||||
data?: any,
|
||||
config?: AxiosRequestConfig
|
||||
): Promise<T | null> {
|
||||
try {
|
||||
// Get saved credentials from Keychain
|
||||
const creds = await Keychain.getGenericPassword();
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
...(creds ? { Authorization: `Bearer ${creds.password}` } : {}),
|
||||
...config?.headers,
|
||||
};
|
||||
|
||||
const response = await axios({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
...config,
|
||||
headers,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
if (error.response) {
|
||||
// Server responded with a status other than 2xx
|
||||
console.error(
|
||||
"API Error:",
|
||||
`Status: ${error.response.status}`,
|
||||
`Data: ${JSON.stringify(error.response.data)}`
|
||||
);
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
console.error("API Error: No response received", error.request);
|
||||
} else {
|
||||
// Something else went wrong while setting up the request
|
||||
console.error("API Error:", error.message);
|
||||
}
|
||||
return null; // return null so the caller can handle it
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export const LOGIN_URL = "https://exotic-humpback-mistakenly.ngrok-free.app/api/user/generate/otp?mobile="
|
||||
export const VARIFY_OTP_URL = "https://exotic-humpback-mistakenly.ngrok-free.app/api/user/otp/verify"
|
||||
export const ORGRAGISTRATION = "https://exotic-humpback-mistakenly.ngrok-free.app/api/organizer/registration/apply "
|
||||
export const ORGRAGISTRATION = "https://exotic-humpback-mistakenly.ngrok-free.app/api/organizer/registration/apply"
|
||||
export const GROUP_CREATION_URL = "https://exotic-humpback-mistakenly.ngrok-free.app/api/group/create"
|
||||
|
||||
Reference in New Issue
Block a user