PageSourceSearch

https://snappilot.ai/assets/js/InstagramCallback-C0HMoZCt.js

js snappilot.ai collected 2026-10-05 12:39:30 UTC 6,592 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-vendor-DeaCpvuz.js";import{h as S,u as F,r as f}from"./react-vendor-BwON9l4R.js";import{o as C,s as h}from"./index-Kz-5MvZ9.js";import"./supabase-vendor-eEOYocAC.js";import"./query-vendor-DsJQQYkK.js";const T=()=>{const[u]=S(),d=F(),[x,o]=f.useState("processing"),[k,n]=f.useState("Connecting your Instagram account..."),[b,w]=f.useState("");return f.useEffect(()=>{(async()=>{const g=u.get("code"),c=u.get("state"),_=u.get("error")||u.get("error_reason"),v=u.get("action"),y=()=>{const t=sessionStorage.getItem("oauth_return_path");if(t)return sessionStorage.removeItem("oauth_return_path"),t;if(c)try{const a=JSON.parse(atob(c));if(a?.returnUrl&&typeof a.returnUrl=="string")return a.returnUrl}catch{}return"/wizard/step1"};if(_==="access_denied"||_==="user_denied"||v==="cancel"){try{sessionStorage.setItem("oauth_cancel_at",Date.now().toString())}catch{}try{const p=sessionStorage.getItem("oauth_session_backup");if(p){const r=JSON.parse(p);r?.access_token&&r?.refresh_token&&await h.auth.setSession({access_token:r.access_token,refresh_token:r.refresh_token}),sessionStorage.removeItem("oauth_session_backup")}}catch{}try{await h.auth.refreshSession()}catch{}const t=y(),a=new URL(t,window.location.origin);a.searchParams.set("oauth","cancel"),window.location.assign(a.toString());return}const{data:{session:P}}=await h.auth.getSession();if(!P){o("error"),n("Session expired. Please log in again."),setTimeout(()=>d("/auth"),2e3);return}if(!g||!c){o("error"),n("Missing authorization code or state"),setTimeout(()=>d(y()),2e3);return}try{const{data:t,error:a}=await h.functions.invoke("instagram-oauth-callback",{body:{code:g,state:c}});if(a){console.error("Instagram OAuth function error:",a);let r="Failed to connect Instagram account.",s="";if(t?.error){const l=t.errorType||"",m=t.error.toLowerCase();l==="missing_permissions"?(r="Missing Required Permissions",s=`Facebook didn't grant these permissions: ${t.missingPermissions?.join(", ")||"unknown permissions"}. Click "Re-authorize" below and make sure to grant all requested permissions.`):l==="no_facebook_pages"||m.includes("no facebook pages")?(r="No Facebook Page Found",s="You need admin access to a Facebook Page. Either you don't have any Pages, or you're not an admin. Create a Page or request admin access."):l==="no_instagram_connected_any_page"||l==="no_instagram_connected"||m.includes("no instagram account connected")?(r="Instagram Not Connected to Page",t.availablePages&&t.availablePages.length>0?s=`Your Facebook Pages (${t.availablePages.map(I=>I.name).join(", ")}) don't have Instagram Business/Creator accounts connected. Go to Page Settings → Instagram → Connect Account.`:s="Your Facebook Page doesn't have an Instagram Business/Creator account connected. Please link your Instagram account in Facebook Page settings."):m.includes("missing oauth parameters")?(r="Authorization Failed",s="The authorization process was interrupted. Please try connecting again."):m.includes("invalid oauth state")?(r="Session Expired",s="Your login session expired during authorization. Please log in and try again."):l==="token_exchange_failed"||m.includes("failed to exchange")?(r="Authorization Code Invalid",s="The authorization code from Facebook was invalid or expired. Please try connecting again."):l==="database_error"?(r="Failed to Save Connection",s="Instagram was authorized but we couldn't save the connection. Please try again."):(r=t.error,s="If this issue persists, make sure your Instagram account is set to Business or Creator mode and connected to a Facebook Page.")}else s="Please check your Instagram account settings and try again. Make sure you have a Business or Creator account connected to a Facebook Page.";o("error"),n(r),w(s);return}if(t?.error)throw new Error(t.error);o("success"),n("Instagram connected successfully! Redirecting..."),sessionStorage.setItem("oauth_completed_at",Date.now().toString());const p=y();setTimeout(()=>d(`${p}?connected=instagram`,{replace:!0}),1500)}catch(t){console.error("Instagram OAuth error:",t),o("error");const a=t instanceof Error?t.message:"Failed to connect Instagram account";n(a),w("If you need help setting up Instagram, check the setup guide on Step 1.")}})()},[u,d]),e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center space-y-4",children:[x==="processing"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-lg text-foreground",children:k})]}),x==="success"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-12 w-12 mx-auto rounded-full bg-green-500 flex items-center justify-center",children:e.jsx("svg",{className:"h-6 w-6 text-white",f
1ill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-lg text-foreground",children:k})]}),x==="error"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-12 w-12 mx-auto rounded-full bg-red-500 flex items-center justify-center",children:e.jsx("svg",{className:"h-6 w-6 text-white",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("p",{className:"text-lg font-semibold text-foreground",children:k}),b&&e.jsx("p",{className:"text-sm text-muted-foreground max-w-md mx-auto mt-2",children:b}),e.jsxs("div",{className:"flex gap-3 mt-6 justify-center",children:[e.jsx("button",{onClick:()=>{const i=sessionStorage.getItem("oauth_return_path")||"/wizard/step1";sessionStorage.removeItem("oauth_return_path"),d(i)},className:"px-6 py-3 bg-secondary text-secondary-foreground rounded-lg hover:bg-secondary/80 transition-colors font-medium",children:"Go Back"}),e.jsx("button",{onClick:async()=>{o("processing"),n("Re-authorizing...");try{const{data:i,error:g}=await h.functions.invoke("instagram-oauth-init-app",{body:{returnUrl:window.location.pathname}});if(g||!i?.authUrl){console.error("Failed to get auth URL:",g),o("error"),n("Failed to start re-authorization");return}const c=new URL(i.authUrl);c.searchParams.set("auth_type","rerequest"),window.location.href=c.toString()}catch(i){console.error("Failed to re-authorize:",i),o("error"),n("Failed to start re-authorization")}},className:"px-6 py-3 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors font-medium",children:"Re-authorize Instagram"})]})]})]})})};export{T as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.