cf32b01356
- Fix issue where different galleries shared authentication - Store gallery tokens with slug-specific keys in localStorage - Remove global gallery_token cookie approach - Each gallery now maintains its own authentication state - Add cleanup for legacy authentication data This ensures that accessing different galleries requires separate authentication and prevents cross-gallery authentication leakage. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { api, setAuthToken, clearAuthToken } from '../config/api';
|
|
import type { LoginResponse, GalleryAuthResponse } from '../types';
|
|
|
|
export const authService = {
|
|
// Admin authentication
|
|
async adminLogin(credentials: { email: string; password: string; recaptchaToken?: string | null }): Promise<LoginResponse> {
|
|
// Backend expects 'username' field, but we accept email
|
|
const response = await api.post<LoginResponse>('/api/auth/admin/login', {
|
|
username: credentials.email,
|
|
password: credentials.password,
|
|
recaptchaToken: credentials.recaptchaToken
|
|
});
|
|
|
|
setAuthToken(response.data.token, true);
|
|
return response.data;
|
|
},
|
|
|
|
adminLogout() {
|
|
clearAuthToken(true);
|
|
window.location.href = '/admin/login';
|
|
},
|
|
|
|
// Gallery authentication
|
|
async verifyGalleryPassword(slug: string, password: string, recaptchaToken?: string | null): Promise<GalleryAuthResponse> {
|
|
const response = await api.post<GalleryAuthResponse>('/api/auth/gallery/verify', {
|
|
slug,
|
|
password,
|
|
recaptchaToken
|
|
});
|
|
|
|
// Token is now handled by GalleryAuthContext with slug-specific storage
|
|
return response.data;
|
|
},
|
|
|
|
galleryLogout() {
|
|
// Logout is now handled by GalleryAuthContext
|
|
},
|
|
}; |