4 lines
9.5 KiB
JavaScript
4 lines
9.5 KiB
JavaScript
module.exports=[95121,a=>{"use strict";var b=a.i(78352),c=a.i(28091),d=a.i(75192),e=a.i(31715);let f=(0,c.createContext)(null);function g({children:a}){let g=(()=>{let{data:a,status:b}=(0,d.useSession)(),[f,g]=(0,c.useState)(null),h="loading"===b;(0,c.useEffect)(()=>{a?.user?g({id:a.user.id||"",email:a.user.email||"",name:a.user.name||"User",subscription:{plan:"free",startDate:Date.now(),status:"active"},usage:{aiActionsCurrent:0,aiActionsLimit:100,projectsLimit:3},preferences:{theme:"light",dailyWordGoal:500,language:"fr"},stats:{totalWordsWritten:0,writingStreak:0,lastWriteDate:0}}):"unauthenticated"===b&&g(null)},[a,b]);let i=(0,c.useCallback)(async(a,b)=>{let c=await (0,d.signIn)("credentials",{email:a,password:b,redirect:!1});if(c?.error)throw Error("CredentialsSignin"===c.error?"Email ou mot de passe incorrect":c.error)},[]),j=(0,c.useCallback)(async(a,b,c)=>{await e.default.auth.register(a,b,c);let f=await (0,d.signIn)("credentials",{email:a,password:b,redirect:!1});if(f?.error)throw Error("Compte créé mais erreur de connexion automatique")},[]),k=(0,c.useCallback)(async()=>{await (0,d.signOut)({redirect:!1}),g(null)},[]),l=(0,c.useCallback)(()=>{f&&g({...f,usage:{...f.usage,aiActionsCurrent:f.usage.aiActionsCurrent+1}})},[f]);return{user:f,login:i,signup:j,logout:k,incrementUsage:l,loading:h}})();return(0,b.jsx)(f.Provider,{value:g,children:a})}function h(){return(0,c.useContext)(f)}a.s(["AuthProvider",0,({children:a})=>(0,b.jsx)(d.SessionProvider,{children:(0,b.jsx)(g,{children:a})}),"useAuthContext",()=>h],95121)},31715,a=>{"use strict";let b={async request(a,b={}){let c=`/api${a}`,d={"Content-Type":"application/json",...b.headers},e=await fetch(c,{...b,headers:d});if(!e.ok){let a=`Error ${e.status}: ${e.statusText}`;try{let b=await e.json();b.error&&(a=b.error),b.message&&(a=b.message)}catch{}throw Error(a)}return 204===e.status?null:e.json()},auth:{register:async(a,c,d)=>b.request("/auth/register",{method:"POST",body:JSON.stringify({email:a,password:c,name:d})})},projects:{list:async()=>b.request("/projects"),get:async a=>b.request(`/projects/${a}`),create:async a=>b.request("/projects",{method:"POST",body:JSON.stringify(a)}),update:async(a,c)=>b.request(`/projects/${a}`,{method:"PUT",body:JSON.stringify(c)}),delete:async a=>b.request(`/projects/${a}`,{method:"DELETE"})},chapters:{create:async a=>b.request("/chapters",{method:"POST",body:JSON.stringify(a)}),update:async(a,c)=>b.request(`/chapters/${a}`,{method:"PUT",body:JSON.stringify(c)}),delete:async a=>b.request(`/chapters/${a}`,{method:"DELETE"})},entities:{create:async a=>b.request("/entities",{method:"POST",body:JSON.stringify(a)}),update:async(a,c)=>b.request(`/entities/${a}`,{method:"PUT",body:JSON.stringify(c)}),delete:async a=>b.request(`/entities/${a}`,{method:"DELETE"})},ideas:{create:async a=>b.request("/ideas",{method:"POST",body:JSON.stringify(a)}),update:async(a,c)=>b.request(`/ideas/${a}`,{method:"PUT",body:JSON.stringify(c)}),delete:async a=>b.request(`/ideas/${a}`,{method:"DELETE"})},ai:{generate:async(a,c,d,e)=>b.request("/ai/generate",{method:"POST",body:JSON.stringify({project:a,chapterId:c,prompt:d,user:e})}),transform:async(a,c,d,e)=>(await b.request("/ai/transform",{method:"POST",body:JSON.stringify({text:a,mode:c,context:d,user:e})})).text}};a.s(["default",0,b])},75192,a=>{"use strict";var b=a.i(78352),c=a.i(28091);class d extends Error{constructor(a,b){a instanceof Error?super(void 0,{cause:{err:a,...a.cause,...b}}):"string"==typeof a?(b instanceof Error&&(b={err:b,...b.cause}),super(a,b)):super(void 0,a),this.name=this.constructor.name,this.type=this.constructor.type??"AuthError",this.kind=this.constructor.kind??"error",Error.captureStackTrace?.(this,this.constructor);const c=`https://errors.authjs.dev#${this.type.toLowerCase()}`;this.message+=`${this.message?". ":""}Read more at ${c}`}}class e extends d{}class f extends d{}async function g(a,b,c,d={}){let f=`${h(b)}/${a}`;try{let a={headers:{"Content-Type":"application/json",...d?.headers?.cookie?{cookie:d.headers.cookie}:{}}};d?.body&&(a.body=JSON.stringify(d.body),a.method="POST");let b=await fetch(f,a),c=await b.json();if(!b.ok)throw c;return c}catch(a){return c.error(new e(a.message,a)),null}}function h(a){return`${a.baseUrlServer}${a.basePathServer}`}function i(){return Math.floor(Date.now()/1e3)}function j(a){let b=new URL("http://localhost:3000/api/auth");a&&!a.startsWith("http")&&(a=`https://${a}`);let c=new URL(a||b),d=("/"===c.pathname?b.pathname:c.pathname).replace(/\/$/,""),e=`${c.origin}${d}`;return{origin:c.origin,host:c.host,path:d,base:e,toString:()=>e}}let k={baseUrl:j(process.env.NEXTAUTH_URL??process.env.VERCEL_URL).origin,basePath:j(process.env.NEXTAUTH_URL).path,baseUrlServer:j(process.env.NEXTAUTH_URL_INTERNAL??process.env.NEXTAUTH_URL??process.env.VERCEL_URL).origin,basePathServer:j(process.env.NEXTAUTH_URL_INTERNAL??process.env.NEXTAUTH_URL).path,_lastSync:0,_session:void 0,_getSession:()=>{}},l=null;function m(){return"u"<typeof BroadcastChannel?{postMessage:()=>{},addEventListener:()=>{},removeEventListener:()=>{},name:"next-auth",onmessage:null,onmessageerror:null,close:()=>{},dispatchEvent:()=>!1}:new BroadcastChannel("next-auth")}function n(){return null===l&&(l=m()),l}let o={debug:console.debug,error:console.error,warn:console.warn},p=c.createContext?.(void 0);function q(a){if(!p)throw Error("React Context is unavailable in Server Components");let b=c.useContext(p),{required:d,onUnauthenticated:e}=a??{},f=d&&"unauthenticated"===b.status;return(c.useEffect(()=>{if(f){let a=`${k.basePath}/signin?${new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href})}`;e?e():window.location.href=a}},[f,e]),f)?{data:b.data,update:b.update,status:"loading"}:b}async function r(a){let b=await g("session",k,o,a);return(a?.broadcast??!0)&&m().postMessage({event:"session",data:{trigger:"getSession"}}),b}async function s(){let a=await g("csrf",k,o);return a?.csrfToken??""}async function t(){return g("providers",k,o)}async function u(a,b,c){let{callbackUrl:d,...e}=b??{},{redirect:f=!0,redirectTo:g=d??window.location.href,...i}=e,j=h(k),l=await t();if(!l){let a=`${j}/error`;window.location.href=a;return}if(!a||!l[a]){let a=`${j}/signin?${new URLSearchParams({callbackUrl:g})}`;window.location.href=a;return}let m=l[a].type;if("webauthn"===m)throw TypeError(`Provider id "${a}" refers to a WebAuthn provider.
|
|
Please use \`import { signIn } from "next-auth/webauthn"\` instead.`);let n=`${j}/${"credentials"===m?"callback":"signin"}/${a}`,o=await s(),p=await fetch(`${n}?${new URLSearchParams(c)}`,{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({...i,csrfToken:o,callbackUrl:g})}),q=await p.json();if(f){let a=q.url??g;window.location.href=a,a.includes("#")&&window.location.reload();return}let r=new URL(q.url).searchParams.get("error")??void 0,u=new URL(q.url).searchParams.get("code")??void 0;return p.ok&&await k._getSession({event:"storage"}),{error:r,code:u,status:p.status,ok:p.ok,url:r?null:q.url}}async function v(a){let{redirect:b=!0,redirectTo:c=a?.callbackUrl??window.location.href}=a??{},d=h(k),e=await s(),f=await fetch(`${d}/signout`,{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({csrfToken:e,callbackUrl:c})}),g=await f.json();if(n().postMessage({event:"session",data:{trigger:"signout"}}),b){let a=g.url??c;window.location.href=a,a.includes("#")&&window.location.reload();return}return await k._getSession({event:"storage"}),g}function w(a){if(!p)throw Error("React Context is unavailable in Server Components");let{children:d,basePath:e,refetchInterval:h,refetchWhenOffline:j}=a;e&&(k.basePath=e);let l=void 0!==a.session;k._lastSync=l?i():0;let[m,q]=c.useState(()=>(l&&(k._session=a.session),a.session)),[t,u]=c.useState(!l);c.useEffect(()=>(k._getSession=async({event:a}={})=>{try{let b="storage"===a;if(b||void 0===k._session){k._lastSync=i(),k._session=await r({broadcast:!b}),q(k._session);return}if(!a||null===k._session||i()<k._lastSync)return;k._lastSync=i(),k._session=await r(),q(k._session)}catch(a){o.error(new f(a.message,a))}finally{u(!1)}},k._getSession(),()=>{k._lastSync=0,k._session=void 0,k._getSession=()=>{}}),[]),c.useEffect(()=>{let a=()=>k._getSession({event:"storage"});return n().addEventListener("message",a),()=>n().removeEventListener("message",a)},[]),c.useEffect(()=>{let{refetchOnWindowFocus:b=!0}=a,c=()=>{b&&"visible"===document.visibilityState&&k._getSession({event:"visibilitychange"})};return document.addEventListener("visibilitychange",c,!1),()=>document.removeEventListener("visibilitychange",c,!1)},[a.refetchOnWindowFocus]);let v=function(){let[a,b]=c.useState("u">typeof navigator&&navigator.onLine),d=()=>b(!0),e=()=>b(!1);return c.useEffect(()=>(window.addEventListener("online",d),window.addEventListener("offline",e),()=>{window.removeEventListener("online",d),window.removeEventListener("offline",e)}),[]),a}(),w=!1!==j||v;c.useEffect(()=>{if(h&&w){let a=setInterval(()=>{k._session&&k._getSession({event:"poll"})},1e3*h);return()=>clearInterval(a)}},[h,w]);let x=c.useMemo(()=>({data:m,status:t?"loading":m?"authenticated":"unauthenticated",async update(a){if(t)return;u(!0);let b=await g("session",k,o,void 0===a?void 0:{body:{csrfToken:await s(),data:a}});return u(!1),b&&(q(b),n().postMessage({event:"session",data:{trigger:"getSession"}})),b}}),[m,t]);return(0,b.jsx)(p.Provider,{value:x,children:d})}a.s(["SessionProvider",()=>w,"signIn",()=>u,"signOut",()=>v,"useSession",()=>q],75192)}];
|
|
|
|
//# sourceMappingURL=Documents_00%20-%20projet_plumeia_6ac9e2a6._.js.map
|