fix: use clipboard mode for Amber login in Capacitor APK
Capacitor native apps fail with "malformed nostrsigner request" when using callbackUrl because Amber treats custom URI schemes as invalid. Fix: detect window.Capacitor.isNativePlatform() and use the no-callback clipboard flow (openAmberForLoginNoCallback) instead of the callbackUrl flow. Amber copies the pubkey to clipboard, app reads it on visibilitychange when user returns. Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
parent
3f654f4a35
commit
55856e2935
1 changed files with 7 additions and 9 deletions
|
|
@ -90,18 +90,16 @@ const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLogin, onS
|
|||
setAmberStep('waiting');
|
||||
setErrors(prev => ({ ...prev, amber: undefined }));
|
||||
|
||||
// Detect if running as installed PWA (standalone) — window.matchMedia
|
||||
// returns true when launched from home screen on Android/iOS
|
||||
// Detect if running as Capacitor native app or installed PWA (standalone)
|
||||
const isCapacitor = !!(window as unknown as { Capacitor?: { isNativePlatform?: () => boolean } }).Capacitor?.isNativePlatform?.();
|
||||
const isPWA = window.matchMedia('(display-mode: standalone)').matches
|
||||
|| ('standalone' in window.navigator && (window.navigator as { standalone?: boolean }).standalone === true);
|
||||
|
||||
if (isPWA) {
|
||||
// ── PWA / Capacitor mode ───────────────────────────────────────────────
|
||||
// When installed to home screen or running as a Capacitor APK, the app
|
||||
// is single-tab. Use openAmberForLogin() which handles Capacitor WebViews
|
||||
// correctly via window.open(_system) instead of window.location.href.
|
||||
// Amber copies the pubkey to clipboard when there's no callback.
|
||||
// When the user comes back, visibilitychange fires and we read the clipboard.
|
||||
if (isCapacitor || isPWA) {
|
||||
// ── Capacitor APK / PWA mode ───────────────────────────────────────────
|
||||
// In Capacitor, callbackUrl flows don't work — Amber treats the custom
|
||||
// scheme as a malformed request. Use no-callback mode: Amber copies the
|
||||
// pubkey to clipboard, we read it when the app regains focus.
|
||||
openAmberForLoginNoCallback();
|
||||
|
||||
// When user returns to the PWA after approving in Amber, auto-read clipboard
|
||||
|
|
|
|||
Loading…
Reference in a new issue