"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[494],{62494:function(e,t,o){o.d(t,{initializeOAuthClient:function(){return l},onSessionDeleted:function(){return d},restoreSession:function(){return c},signIn:function(){return a},signOut:function(){return u}});var n=o(16297);let s={client_id:"https://flushes.app/client-metadata.json",application_type:"web",client_name:"Flushes",client_uri:"https://flushes.app",logo_uri:"https://flushes.app/logo.png",tos_uri:"https://flushes.app/terms",policy_uri:"https://flushes.app/privacy",dpop_bound_access_tokens:!0,grant_types:["authorization_code","refresh_token"],redirect_uris:["https://flushes.app/auth/callback"],response_types:["code"],scope:"atproto transition:generic",token_endpoint_auth_method:"none"},i=null;function r(){return i||(i=new n.BrowserOAuthClient({clientMetadata:s,handleResolver:"https://bsky.social",responseMode:"fragment"})),i}async function l(){try{let e=r(),t=await e.init();if(t){let{session:e}=t,o="state"in t?t.state:null;return console.log("OAuth client initialized with session for ".concat(e.sub)),o?console.log("User successfully authenticated with state: ".concat(o)):console.log("Restored previous session"),{session:e,state:o}}return console.log("OAuth client initialized without existing session"),null}catch(e){throw console.error("Failed to initialize OAuth client:",e),e}}async function a(e,t){try{console.log("Initiating OAuth flow for ".concat(e));let o=r();await o.signIn(e,{state:(null==t?void 0:t.state)||"signin-".concat(Date.now()),signal:null==t?void 0:t.signal})}catch(e){throw console.error("OAuth sign in failed:",e),e}}async function c(e){try{console.log("Restoring session for ".concat(e));let t=r(),o=await t.restore(e);return console.log("Successfully restored session for ".concat(o.sub)),o}catch(t){throw console.error("Failed to restore session for ".concat(e,":"),t),t}}async function u(){try{console.log("Signing out user"),"undefined"!=typeof localStorage&&(localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken"),localStorage.removeItem("did"),localStorage.removeItem("handle"),localStorage.removeItem("keyPair"),localStorage.removeItem("dpopNonce"),localStorage.removeItem("pdsEndpoint"),localStorage.removeItem("bsky_auth_pdsEndpoint")),console.log("User signed out")}catch(e){throw console.error("Error during sign out:",e),e}}function d(e){try{r().addEventListener("deleted",t=>{let{sub:o,cause:n}=t.detail;console.error("Session for ".concat(o," was invalidated:"),n),e({sub:o,cause:n})})}catch(e){console.error("Failed to set up session deleted listener:",e)}}}}]);