winofy-front/src/app
Afra ‌ 573f43ea41 fix: self-healing session — stale/expired sessions no longer crash the app
Root cause of the home-page 500 ("اطلاعات برای اعتبارسنجی ارسال نشده است",
401 not_authenticated): getSession() only decrypted the session cookie, it
never checked whether the access token inside it had actually expired. The
JWE wrapper lives 30 days; the real Gooyal access token lives ~10 hours
(expires_in: 36000). So isAuthenticated stayed true long after the token
died, the home page called getCart() anyway, winofyFetch's refresh attempt
failed silently (dead refresh token) and returned no Authorization header
at all, and the resulting 401 was never caught -- crashing the whole page.

Fix: getValidSession() (session.ts) is now the single source of truth --
refreshes when possible, self-heals by clearing the cookie when refresh
fails, deduped per-request via React's cache(). winofyFetch and every
isAuthenticated check (home page, shop layout) now use it instead of the
raw cookie read.

That surfaced a second bug: Next.js forbids writing cookies during a plain
Server Component render (Server Actions/Route Handlers only), so
getValidSession()'s self-heal itself crashed when called from a page like
home. createSession()/deleteSession() now swallow that specific failure --
the refreshed/cleared session is still correct for the rest of the current
request, it just won't persist when called from a context that can't write
cookies (the next request re-derives the same correct answer).

Also added requireSession(path) and wired it into every auth-required page
(cart, checkout, addresses, orders, order-groups/[uuid], profile) --
proxy.ts's gate is deliberately optimistic (cookie presence only, per
Next.js's own guidance), so a present-but-dead session was reaching these
pages and crashing the same way; they now redirect to /login instead.

Verified against the exact failure: a session with a dead access+refresh
token now renders the home page as logged-out (200, not 500) and redirects
/cart to /login (307) instead of crashing. Also verified the happy path
(a genuinely fresh, valid session from a real OTP login) still works.
2026-08-19 10:26:02 +03:30
..
(auth)/login feat: guest-home/C04 shell, location onboarding (L01/L04/L06), profile placeholder 2026-08-17 17:24:27 +03:30
(customer) fix: self-healing session — stale/expired sessions no longer crash the app 2026-08-19 10:26:02 +03:30
(seller)/seller feat: real design system tokens + C01/C02/C03 login-OTP flow per winofyfrontenddoc.md 2026-08-17 14:10:27 +03:30
api/auth feat: customer shopping flow (store/product pages, cart, addresses, checkout, order tracking); auth calls Gooyal directly from browser 2026-08-17 10:19:59 +03:30
favicon.ico Initial commit from Create Next App 2026-08-15 14:44:07 +03:30
globals.css feat: real design system tokens + C01/C02/C03 login-OTP flow per winofyfrontenddoc.md 2026-08-17 14:10:27 +03:30
layout.tsx feat: real design system tokens + C01/C02/C03 login-OTP flow per winofyfrontenddoc.md 2026-08-17 14:10:27 +03:30