Refactor authentication and user data handling in Index, Profile, and Schedule components to use token-based authentication and improve error handling

This commit is contained in:
2025-07-28 13:31:06 +02:00
parent dd6627ae35
commit ccc8b00348
3 changed files with 73 additions and 75 deletions

View File

@@ -21,40 +21,31 @@ export default function Schedule() {
async function fetchWorkdays() {
setLoading(true);
try {
const userCookieRaw = await SecureStore.getItemAsync('cookie');
if (!userCookieRaw) {
throw new Error('Nincs elmentett cookie, kérlek jelentkezz be újra!');
const token = await SecureStore.getItemAsync('token');
if (!token) {
throw new Error('Nincs elmentett token, kérlek jelentkezz be újra!');
}
const userCookie = userCookieRaw.split(';')[0];
const year = getYear(currentMonth);
const month = getMonth(currentMonth) + 1;
console.log(userCookie)
const response = await fetch(`https://mymenu.mcdonalds.hu/api/UserDataApi/GetWorkDayMonthList`, {
method: 'POST',
const response = await fetch(`https://menuapi.devbeni.lol/api/@me/schedule?year=${year}&month=${month}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
cookie: userCookie,
origin: 'https://mymenu.mcdonalds.hu',
'Authorization': `Bearer ${token}`,
'Accept': 'application/json',
},
body: JSON.stringify({
Data: {
Year: year,
Month: month
}
})
});
const data = await response.json();
console.log('API teljes válasz:', data);
if (!data || !data.data || !data.data.Data) {
if (!data || !data.data || !Array.isArray(data.data.Data)) {
console.log('Nincs beosztás adat a válaszban!');
setWorkdays([]);
return;
}
setWorkdays(data.data.Data);
} catch (e) {
const err = e as any;