update api

This commit is contained in:
2025-02-10 12:27:51 +05:30
parent b9a902507e
commit d56678786b
3 changed files with 35 additions and 15 deletions

4
.env
View File

@@ -1,2 +1,4 @@
VITE_API_URL=https://ssa.betadelivery.com/apia
VITE_API_URL=https://ssa.betadelivery.com/apia/v1
VITE_USER_NAME="Admin"
VITE_PASSWORD="71%@L%es^bUX94`J9XT*%4&^%tUU^%Q^ffgt"
VITE_APP_NAME=MyViteApp

View File

@@ -29,25 +29,43 @@ const Login = () => {
formState: { errors },
} = useForm<FormValues>()
const onSubmit = handleSubmit(async (data) => {
setIsLoading(true)
setIsLoading(true);
// Encode Basic Auth Credentials
const username = import.meta.env.VITE_USER_NAME||''; // Replace with actual username
const password = import.meta.env.VITE_PASSWORD||''; // Replace with actual password
const basicAuth = btoa(`${username}:${password}`); // Encode to Base64
try {
const response = await axios.post(`${import.meta.env.VITE_API_URL}/v1/login`, {
mobile_number: data.mobileNumber,
password: data.password,
});
console.log('====================================');
const response = await axios.post(
`${import.meta.env.VITE_API_URL}/v1/login`,
{
mobile_number: data.mobileNumber,
password: data.password,
},
{
headers: {
Authorization: `Basic ${basicAuth}`,
"Content-Type": "application/json",
},
}
);
console.log("====================================");
console.log(response);
console.log('====================================');
console.log("====================================");
dispatch(setToken(String(response.data["access-token"])));
} catch (error) {
console.error("Login failed", error);
if (error) {
console.error("Login failed", error);
setIsLoading(false)
}
}
});

View File

@@ -4,7 +4,7 @@ import { logout } from "./authSlice"; // Import logout action from authSlice
import { RootState } from "../Store";
const baseQuery = fetchBaseQuery({
baseUrl: "https://api.example.com",
baseUrl: `${import.meta.env.VITE_API_URL}`,
prepareHeaders: (headers, { getState }) => {
const token = (getState() as RootState).auth.token; // Get token from Redux store
if (token) {
@@ -42,7 +42,7 @@ export const apiSlice = createApi({
}),
});