fix: not adding subdomain address to fetch api
All checks were successful
Update changelog / changelog (push) Successful in 28s
All checks were successful
Update changelog / changelog (push) Successful in 28s
This commit is contained in:
@@ -3,9 +3,6 @@ import { AuthContext } from './AuthContext';
|
||||
import { sha512 } from '../utils/crypto';
|
||||
import type { AuthResponse } from '../types/auth';
|
||||
|
||||
/**
|
||||
* Funkcja pomocnicza do pobierania subdomeny.
|
||||
*/
|
||||
const getSubdomain = (): string | null => {
|
||||
const hostname = window.location.hostname;
|
||||
const parts = hostname.split('.');
|
||||
@@ -28,22 +25,21 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
try {
|
||||
const hashedPassword = await sha512(pass);
|
||||
|
||||
// Korzystamy z relatywnej ścieżki /api, którą Vite Proxy przekaże dalej.
|
||||
// Usuwamy API_BASE_URL, aby uniknąć błędów o nieużywanej zmiennej.
|
||||
const pathPrefix = subdomain ? `/api/${subdomain}` : '/api';
|
||||
const fullUrl = `${pathPrefix}/v1/user/${endpoint}`;
|
||||
// POPRAWKA: Ścieżka URL jest stała, zgodna z Twoim API.
|
||||
// Vite Proxy przechwyci '/api' i skieruje to na https://www.ktty.is
|
||||
const fullUrl = `/api/v1/user/${endpoint}`;
|
||||
|
||||
const response = await fetch(fullUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
// Subdomenę przekazujemy w nagłówku, aby backend wiedział, który to klient
|
||||
'X-Subdomain': subdomain || '',
|
||||
},
|
||||
body: JSON.stringify({ name, password: hashedPassword, ttl: 86400 }),
|
||||
});
|
||||
|
||||
// Rozwiązanie błędu "Unexpected any": definiujemy typ danych przed użyciem
|
||||
const data: AuthResponse = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -57,15 +53,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
return data;
|
||||
} catch (err: unknown) {
|
||||
// Rozwiązanie błędu "Unexpected any" w bloku catch:
|
||||
let errorMessage = 'Wystąpił nieoczekiwany błąd';
|
||||
|
||||
if (err instanceof Error) {
|
||||
errorMessage = err.message;
|
||||
} else if (typeof err === 'string') {
|
||||
errorMessage = err;
|
||||
}
|
||||
|
||||
if (err instanceof Error) errorMessage = err.message;
|
||||
setError(errorMessage);
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user