update api
This commit is contained in:
4
.env
4
.env
@@ -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
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user