login axios

This commit is contained in:
IluaAir
2025-10-09 22:51:50 +03:00
parent 15426adc69
commit 4fe2d39fba

View File

@@ -1,5 +1,6 @@
import client from './client';
import { API_ENDPOINTS } from './ApiSources';
import { getFingerprint } from './fingerprint';
/**
@@ -51,3 +52,32 @@ export const logout = async () => {
throw error.response?.data || error.message;
}
};
/**
* User login
* @param {string} username - Username
* @param {string} password - Password
* @returns {Promise<Object>} Login result
*/
export const login = async (username, password) => {
try {
const fingerprint = await getFingerprint();
const formData = new FormData();
formData.append('username', username);
formData.append('password', password);
formData.append('fingerprint', fingerprint);
const response = await client.post(API_ENDPOINTS.AUTH.LOGIN, formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
});
console.log(response.data);
if (response.data.access_token && response.data.token_type === 'bearer') {
localStorage.setItem('access_token', response.data.access_token);
}
return response.data;
} catch (error) {
throw error.response?.data || error.message;
}
};