login axios
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user