Files
MyIP/frontend/utils/auth-flow.js
T
Claude 08473e3e54 Fix(auth): sign in by redirect inside the installed PWA
An iOS standalone PWA has no popup with a usable opener, so
signInWithPopup never delivered its result there: the provider sent
the visitor back to the homepage and the app saw no sign-in. The store
now picks the flow (utils/auth-flow.js): popup in a browser tab, as
before; signInWithRedirect in the installed PWA, and as the fallback
when a popup is blocked. A redirect marks its provider in sessionStorage
(utils/auth-redirect.js) and boot consumes the marker before first
render with getRedirectResult, so the first authenticatedFetch carries
the token like the signed-in boot path. The toast host now shows an
alert raised before mount, which a failed redirect return is.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GbLTGMZ45MV78qd2tHoco
2026-10-05 14:50:45 +00:00

18 lines
826 B
JavaScript

// Sign-in flow choice: popup or full-page redirect.
// An installed PWA (iOS standalone above all) has no popup with a usable
// `opener`, so the provider's result could never be posted back — it signs
// in by redirect instead, consumed at boot via utils/auth-redirect.js. A
// browser tab keeps the popup and falls back to the redirect only when the
// popup itself can't open.
// Popup rejections that mean "this environment can't do popups", as opposed
// to the visitor closing or superseding one.
const REDIRECT_FALLBACK_CODES = new Set([
'auth/popup-blocked',
'auth/operation-not-supported-in-this-environment',
]);
export const resolveSignInFlow = ({ runningAsPwa }) => (runningAsPwa ? 'redirect' : 'popup');
export const shouldFallBackToRedirect = (errorCode) => REDIRECT_FALLBACK_CODES.has(errorCode);