1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9179],{79179:function(e,t,n){n.d(t,{Ho:function(){return g},aC:function(){return h},do:function(){return c}});var i=n(57437),r=n(2265),o=n(99204),a=n(44954),u=n(84278),l=n(83125);let s=u.CE;function c(){return(0,l.xP)()?window.location.origin:(0,o.r9)()}let d=(0,r.createContext)(null),f="X-Long-Session",p="X-PWA-Client";function g(e){let{children:t,isPwa:n=!1}=e,[g,h]=(0,r.useState)(null),[m,w]=(0,r.useState)(null),[_,k]=(0,r.useState)(!0),v=(0,r.useCallback)(e=>{e?(localStorage.setItem(s,e),(0,o.Mt)(e)):(localStorage.removeItem(s),(0,o.Os)()),w(e),e||h(null)},[]),b=(0,r.useCallback)(async()=>{let e=localStorage.getItem(s);if(!e){w(null),h(null),(0,o.Os)(),k(!1);return}w(e);let t="".concat(c(),"/api/auth/me"),n={Authorization:"Bearer ".concat(e)};(0,l.xP)()&&(n[p]="1");try{let e=await fetch(t,{headers:n,credentials:"include"});if(e.ok){var i,r,a,d,f,g,m,_;let t=(await e.json()).user;h({id:t.id,email:null!==(i=t.email)&&void 0!==i?i:null,name:null!==(r=t.display_name)&&void 0!==r?r:t.email,display_name:t.display_name,image:null!==(d=null!==(a=t.profile_image)&&void 0!==a?a:t.image)&&void 0!==d?d:null,bio:null!=t.bio&&""!==t.bio?String(t.bio):null,role:t.role,moderator_level:t.moderator_level,is_verified:t.is_verified,bulk_import_enabled:null!==(f=t.bulk_import_enabled)&&void 0!==f&&f,field_mode_enabled:null!==(g=t.field_mode_enabled)&&void 0!==g&&g,sorting_office_enabled:!1!==t.sorting_office_enabled,challenges_enabled:null!==(m=t.challenges_enabled)&&void 0!==m&&m,ads_free:!0===t.ads_free,needs_signup_source:null!==(_=t.needs_signup_source)&&void 0!==_&&_,auto_approve:!0===t.auto_approve,uploads_approved:Math.max(0,Math.floor(Number(t.uploads_approved)||0)),corrections_approved:Math.max(0,Math.floor(Number(t.corrections_approved)||0)),login_count:Math.max(0,Math.floor(Number(t.login_count)||0)),has_testimonial:!0===t.has_testimonial,moderator_application_status:"pending"===t.moderator_application_status||"approved"===t.moderator_application_status||"rejected"===t.moderator_application_status?t.moderator_application_status:null});let n=localStorage.getItem(s);n&&(0,o.Mt)(n)}else(0,u.aG)(e.status)&&(localStorage.removeItem(s),(0,o.Os)(),w(null),h(null))}catch(e){}finally{k(!1)}},[]);(0,r.useEffect)(()=>{b()},[b]),(0,r.useEffect)(()=>{let e=()=>{if(!_&&!g){try{if(!localStorage.getItem(s))return}catch(e){return}b()}},t=()=>{"visible"===document.visibilityState&&e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}},[_,g,b]),(0,r.useEffect)(()=>{let e=e=>{let t=e.trim();t&&(v(t),b())},t=t=>{let n=(0,u.RI)(t.detail);n&&e(n)};return window.PostboxMapNativeSite={...window.PostboxMapNativeSite||{},setSessionToken:t=>{"string"==typeof t&&e(t)}},window.addEventListener(u.Ji,t),()=>{window.removeEventListener(u.Ji,t),window.PostboxMapNativeSite&&delete window.PostboxMapNativeSite.setSessionToken}},[v,b]),(0,r.useEffect)(()=>{if(!g)return;let e=()=>{"undefined"!=typeof document&&document.hasFocus()&&o.x1.pingActivity().catch(()=>{})},t=window.setTimeout(e,12e4),n=window.setInterval(e,3e5);return()=>{window.clearTimeout(t),window.clearInterval(n)}},[g,12e4,3e5]);let y=(0,r.useCallback)(async(e,t)=>{let i=c(),r="".concat(i,"/api/auth/login"),a={"Content-Type":"application/json"};(n||(0,l.xP)())&&(a[f]="true"),(0,l.xP)()&&(a[p]="1");let u=()=>fetch(r,{method:"POST",headers:a,body:JSON.stringify({email:e,password:t}),credentials:"include"});for(let e=0;e<2;e++)try{e>0&&await new Promise(e=>setTimeout(e,600));let t=await u(),i=await t.json().catch(()=>({}));if(!t.ok){let e=i.error||i.message||"Login failed";return{ok:!1,error:(0,o.gS)(e,"Login failed"),code:i.code}}if(i.requires_mfa&&i.mfa_token)return{ok:!1,requiresMfa:!0,mfaToken:i.mfa_token};let r=i.token;if(r&&(v(r),await b()),!r&&(n||(0,l.xP)()))return{ok:!1,error:"Server returned an invalid response. Try again or sign in on the website."};return{ok:!!r}}catch(t){if(0===e&&(0,o.QI)(t)&&(n||(0,l.xP)()))continue;
1return{ok:!1,error:(0,o.i)(t,"Login failed")}}return{ok:!1,error:o.Oi}},[v,b,n]),S=(0,r.useCallback)(async(e,t)=>{let i=c(),r="".concat(i,"/api/auth/google"),a={"Content-Type":"application/json"};(n||(0,l.xP)())&&(a[f]="true"),(0,l.xP)()&&(a[p]="1");let u={id_token:e,signup_platform:(0,l.aj)()};(null==t?void 0:t.signup_source)&&(u.signup_source=t.signup_source,t.signup_source_detail&&(u.signup_source_detail=t.signup_source_detail));let s=()=>fetch(r,{method:"POST",headers:a,body:JSON.stringify(u),credentials:"include"}),d=null;for(let e=0;e<3;e++)try{e>0&&await new Promise(t=>setTimeout(t,400+300*e));let t=await s(),i=await t.json().catch(()=>({}));if(!t.ok){if(403===t.status&&"NEED_PASSWORD_TO_LINK"===i.code&&i.link_token)return{ok:!1,code:i.code,needPasswordToLink:!0,linkToken:i.link_token,error:i.message||i.error};return{ok:!1,error:i.error||"Google sign-in failed",code:i.code}}if(i.requires_mfa&&i.mfa_token)return{ok:!1,requiresMfa:!0,mfaToken:i.mfa_token};let r=i.token;if(r&&(v(r),await b()),!r&&(n||(0,l.xP)()))return{ok:!1,error:"Server returned an invalid response. Try again or sign in on the website."};return{ok:!!r,newOauthSignup:!!i.new_oauth_signup,needsSignupSource:!!i.needs_signup_source}}catch(e){d=e instanceof Error?e:Error("Google sign-in failed")}return{ok:!1,error:(0,o.i)(d,"Google sign-in failed. Try again or sign in with email and password.")}},[v,b,n]),P=(0,r.useCallback)(async(e,t)=>{try{let i=c(),r={"Content-Type":"application/json"};(n||(0,l.xP)())&&(r[f]="true"),(0,l.xP)()&&(r[p]="1");let o=await fetch("".concat(i,"/api/auth/link-account"),{method:"POST",headers:r,body:JSON.stringify({link_token:e,password:t})}),a=await o.json().catch(()=>({}));if(!o.ok)return{ok:!1,error:a.error||"Link account failed"};if(a.requires_mfa&&a.mfa_token)return{ok:!1,requiresMfa:!0,mfaToken:a.mfa_token};let u=a.token;return u&&(v(u),await b()),{ok:!!u}}catch(e){return{ok:!1,error:(0,o.i)(e,"Link account failed")}}},[v,b,n]),x=(0,r.useCallback)(async(e,t)=>{try{let i=c(),r={"Content-Type":"application/json"};(n||(0,l.xP)())&&(r[f]="true"),(0,l.xP)()&&(r[p]="1");let o=await fetch("".concat(i,"/api/auth/mfa/verify"),{method:"POST",headers:r,body:JSON.stringify({mfa_token:e,code:t})}),a=await o.json().catch(()=>({}));if(!o.ok)return{ok:!1,error:a.error||"Invalid code"};let u=a.token;return u&&(v(u),await b()),{ok:!!u}}catch(e){return{ok:!1,error:(0,o.i)(e,"MFA verification failed")}}},[v,b,n]),T=(0,r.useCallback)(async(e,t,i)=>{let r=c(),a={"Content-Type":"application/json"};(0,l.xP)()&&(a[p]="1");for(let u=0;u<2;u++)try{u>0&&await new Promise(e=>setTimeout(e,600));let n=await fetch("".concat(r,"/api/auth/register"),{method:"POST",headers:a,body:JSON.stringify({email:e,display_name:t,password:i,signup_platform:(0,l.aj)()})}),s=await n.json().catch(()=>({}));if(!n.ok)return{ok:!1,error:(0,o.gS)(s.error,"Registration failed"),suggestions:Array.isArray(s.suggestions)?s.suggestions:void 0};return{ok:!0,emailVerificationRequired:s.email_verification_required}}catch(e){if(0===u&&(0,o.QI)(e)&&(n||(0,l.xP)()))continue;return{ok:!1,error:(0,o.i)(e,"Registration failed")}}return{ok:!1,error:o.Oi}},[n]),N=(0,r.useCallback)(()=>{{let e=localStorage.getItem(s);(0,a.VG)().catch(()=>{}),e&&fetch("".concat(c(),"/api/auth/logout"),{method:"POST",headers:{Authorization:"Bearer ".concat(e)},credentials:"include"}).catch(()=>{}),localStorage.removeItem(s),(0,o.Os)(),(0,o.lS)(),w(null),h(null),window.location.href="/login"}},[v]),O=_?"loading":g?"authenticated":"unauthenticated";return(0,i.jsx)(d.Provider,{value:{user:g,token:m,loading:_,status:O,login:y,loginWithGoogle:S,linkAccount:P,loginMfaVerify:x,register:T,logout:N,setToken:v,refreshUser:b},children:t})}function h(){let e=(0,r.useContext)(d);if(!e)throw Error("useAuth must be used within AuthProvider");return e}},84278:function(e,t,n){n.d(t,{CE:function(){return r},Ji:function(){return i},RI:function(){return a},aG:function(){return o}});let i="postboxmap:native-session",r="token";function o(e){return 401===e}function a(e){if(!e||"object"!=typeof e)return null;let t=e.token;if("string"!=typeof t)return null;let n=t.trim();return n.length>0?n:null}},44954:function(e,t,n){n.d(t,{AD:function(){return u},Hd:function(){return o},VG:function(){return s},YV:function(){return c},id:function(){return l},we:function(){return a}});var i=n(99204),r=n(83125);function o(){return window.isSecureContext&&"Notification"in window&&"serviceWorker"
1in navigator&&"PushManager"in window}function a(){let e=window.navigator.userAgent;return/iPad|iPhone|iPod/.test(e)&&!(0,r.xP)()}async function u(){return o()?Notification.permission:"unsupported"}async function l(){if(!o())throw Error("Push notifications are not supported on this device.");let e=await navigator.serviceWorker.ready,t=await e.pushManager.getSubscription();if(t)return await i.x1.savePushSubscription(t.toJSON()),{endpoint:t.endpoint};let{publicKey:n}=await i.x1.getPushVapidPublicKey();if(!n)throw Error("Push notifications are not configured on the server.");let r=await Notification.requestPermission();if("granted"!==r)throw Error("denied"===r?"Notifications are blocked in your browser settings.":"Notification permission was not granted.");let a=await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){let t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(n),r=new Uint8Array(i.length);for(let e=0;e<i.length;e+=1)r[e]=i.charCodeAt(e);return r}(n)});return await i.x1.savePushSubscription(a.toJSON()),{endpoint:a.endpoint}}async function s(){if(!("serviceWorker"in navigator))return;let e=await navigator.serviceWorker.ready.catch(()=>null),t=await (null==e?void 0:e.pushManager.getSubscription()),n=null==t?void 0:t.endpoint;t&&await t.unsubscribe().catch(()=>{}),await i.x1.deletePushSubscription(n)}async function c(){if(!o()||"granted"!==Notification.permission)return!1;let e=await navigator.serviceWorker.ready.catch(()=>null);if(!e)return!1;let t=await e.pushManager.getSubscription();return!!t&&(await i.x1.savePushSubscription(t.toJSON()),!0)}}}]);
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.