mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-29 02:18:49 +05:00
Authorization, favorites and players have been moved to the API server
This commit is contained in:
@@ -13,6 +13,25 @@ export const api = axios.create({
|
||||
}
|
||||
});
|
||||
|
||||
// Attach JWT token if present in localStorage
|
||||
if (typeof window !== 'undefined') {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Update stored token on login response with { token }
|
||||
api.interceptors.response.use((response) => {
|
||||
if (response.config.url?.includes('/auth/login') && response.data?.token) {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('token', response.data.token);
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${response.data.token}`;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
});
|
||||
|
||||
export interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
@@ -41,6 +60,7 @@ export interface Movie {
|
||||
export interface MovieDetails extends Movie {
|
||||
genres: Genre[];
|
||||
runtime: number;
|
||||
imdb_id?: string | null;
|
||||
tagline: string;
|
||||
budget: number;
|
||||
revenue: number;
|
||||
|
||||
16
src/lib/authApi.ts
Normal file
16
src/lib/authApi.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { api } from './api';
|
||||
|
||||
export const authAPI = {
|
||||
register(data: { email: string; password: string; name?: string }) {
|
||||
return api.post('/auth/register', data);
|
||||
},
|
||||
resendCode(email: string) {
|
||||
return api.post('/auth/resend-code', { email });
|
||||
},
|
||||
verify(email: string, code: string) {
|
||||
return api.put('/auth/verify', { email, code });
|
||||
},
|
||||
login(email: string, password: string) {
|
||||
return api.post('/auth/login', { email, password });
|
||||
}
|
||||
};
|
||||
@@ -1,30 +1,24 @@
|
||||
import axios from 'axios';
|
||||
import { api } from './api';
|
||||
|
||||
// Создаем экземпляр axios
|
||||
const api = axios.create({
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
export const favoritesAPI = {
|
||||
// Получить все избранные
|
||||
getFavorites() {
|
||||
return api.get('/api/favorites');
|
||||
return api.get('/favorites');
|
||||
},
|
||||
|
||||
// Добавить в избранное
|
||||
addFavorite(data: { mediaId: string; mediaType: 'movie' | 'tv'; title: string; posterPath?: string }) {
|
||||
return api.post('/api/favorites', data);
|
||||
addFavorite(data: { mediaId: string; mediaType: 'movie' | 'tv', title: string, posterPath: string }) {
|
||||
return api.post(`/favorites`, data);
|
||||
},
|
||||
|
||||
// Удалить из избранного
|
||||
removeFavorite(mediaId: string, mediaType: 'movie' | 'tv') {
|
||||
return api.delete(`/api/favorites/${mediaId}?mediaType=${mediaType}`);
|
||||
removeFavorite(mediaId: string) {
|
||||
return api.delete(`/favorites/${mediaId}`);
|
||||
},
|
||||
|
||||
// Проверить есть ли в избранном
|
||||
checkFavorite(mediaId: string, mediaType: 'movie' | 'tv') {
|
||||
return api.get(`/api/favorites/check/${mediaId}?mediaType=${mediaType}`);
|
||||
checkFavorite(mediaId: string) {
|
||||
return api.get(`/favorites/check/${mediaId}`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user