Fase 2: Implementación de Login, Store de Autenticación, Ruteo y Layout Protegido
This commit is contained in:
15
frontend/admin-panel/src/services/api.ts
Normal file
15
frontend/admin-panel/src/services/api.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'https://localhost:7034/api', // Puerto HTTPS obtenido de launchSettings.json
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export default api;
|
||||
8
frontend/admin-panel/src/services/authService.ts
Normal file
8
frontend/admin-panel/src/services/authService.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import api from './api';
|
||||
|
||||
export const authService = {
|
||||
login: async (username: string, password: string): Promise<string> => {
|
||||
const response = await api.post('/auth/login', { username, password });
|
||||
return response.data.token;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user