1 line
7.6 KiB
JavaScript
Vendored
1 line
7.6 KiB
JavaScript
Vendored
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[989],{989:function(e,t,n){"use strict";n.r(t),n.d(t,{AuthModal:function(){return F}});var a=n(85893),s=n(3243),r=n(4480),i=n(4511),o=n(83725),d=n(73745),c=n(69361),l=n(77889),u=n(68175),h=n(14424),p=n(51095),y=n(5152),f=n.n(y),m=n(67294),j=n(88735);let{Panel:g}=o.default,{Link:x}=d.default,v=f()(()=>Promise.all([n.e(3908),n.e(4804)]).then(n.t.bind(n,74804,23)),{loadableGenerated:{webpack:()=>[74804]},ssr:!1}),b=e=>{let{authenticated:t,displayName:n,accessToken:s}=e,[r,i]=(0,m.useState)(null),[d,y]=(0,m.useState)(!1),[f,b]=(0,m.useState)(!1),[w,A]=(0,m.useState)(""),I=t?(0,a.jsxs)("span",{children:[(0,a.jsx)("b",{children:"You are already authenticated"}),". However, you can add other domains or log in as a different user."]}):(0,a.jsxs)("span",{children:["Use your own domain to authenticate ",(0,a.jsx)("span",{children:n})," or login as a previously"," ","authenticated chat user using IndieAuth."]}),S=r;S&&S.includes("url does not support indieauth")&&(S="The provided URL is either invalid or does not support IndieAuth.");let k=e=>{if(!(0,j.jv)(e)||!e.includes(".")){b(!1);return}b(!0)},_=async()=>{if(f){y(!0);try{let e="https://".concat(w),t=await fetch("/api/auth/indieauth?accessToken=".concat(s),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({authHost:e})}),n=await t.json();if(n.message){i(n.message),y(!1);return}if(!n.redirect){i("Auth provider did not return a redirect URL."),y(!1);return}if(n.redirect){let{redirect:e}=n;window.location=e}}catch(e){i(e.message)}y(!1)}};return(0,a.jsx)(c.Z,{spinning:d,children:(0,a.jsxs)(l.Z,{direction:"vertical",children:[I,S&&(0,a.jsx)(u.Z,{message:"Error",description:S,type:"error",showIcon:!0}),(0,a.jsx)("div",{children:"Your domain"}),(0,a.jsx)(h.default.Search,{addonBefore:"https://",onInput:e=>{":"!==e.nativeEvent.data&&(A(e.target.value),k("https://".concat(e.target.value)))},type:"url",value:w,placeholder:"yoursite.com",status:!f&&w.length>0?"error":void 0,onSearch:_,enterButton:(0,a.jsx)(p.Z,{type:f?"primary":"default",disabled:!f||0===w.length,children:(0,a.jsx)(v,{})})}),(0,a.jsx)(o.default,{ghost:!0,children:(0,a.jsxs)(g,{header:"Learn more about using IndieAuth to authenticate with chat.",children:[(0,a.jsx)("p",{children:"IndieAuth allows for a completely independent and decentralized way of identifying yourself using your own domain."}),(0,a.jsxs)("p",{children:["If you run an Owncast instance, you can use that domain here. Otherwise,"," ",(0,a.jsx)(x,{href:"https://indieauth.net/#providers",children:"learn more about how you can support IndieAuth"}),"."]})]},"header")}),(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:"Note"}),": This is for authentication purposes only, and no personal information will be accessed or stored."]})]})})};var w=n(23772),A=n.n(w);let{Panel:I}=o.default,S=f()(()=>Promise.all([n.e(3908),n.e(4804)]).then(n.t.bind(n,74804,23)),{loadableGenerated:{webpack:()=>[74804]},ssr:!1}),k=e=>{let{authenticated:t,displayName:n,accessToken:s}=e,[r,i]=(0,m.useState)(null),[d,y]=(0,m.useState)(!1),[f,g]=(0,m.useState)(!1),[x,v]=(0,m.useState)(""),[b,w]=(0,m.useState)(""),[k,_]=(0,m.useState)(!1),N=t?(0,a.jsxs)("span",{children:[(0,a.jsx)("b",{children:"You are already authenticated"}),". However, you can add other domains or log in as a different user."]}):(0,a.jsxs)("span",{children:["Receive a direct message on the Fediverse to link your account to"," ",(0,a.jsx)("strong",{children:n}),", or login as a previously linked chat user."]}),C=r;C&&C.includes("url does not support indieauth")&&(C="The provided URL is either invalid or does not support IndieAuth.");let T=e=>{g((0,j.ME)(e))},F=async(e,t)=>{let n=await fetch(e,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(t)}),a=await n.json();a.message&&(i(a.message),y(!1))},Z=async()=>{y(!0);try{await F("/api/auth/fediverse/verify?accessToken=".concat(s),{code:b}),window.location.href="/"}catch(e){console.error(e),i(e)}y(!1)},L=async()=>{if(!f)return;y(!0),i(null);let e=x.replace(/^@+/,"");try{await F("/api/auth/fediverse?accessToken=".concat(s),{account:e}),_(!0)}catch(e){console.error(e),i(e)}y(!1)},M=(0,a.jsxs)("div",{children:["Paste in the code that was sent to your Fediverse account. If you did not receive a code, make sure you can accept direct messages.",(0,a.jsxs)("div",{className:A().codeInputContainer,children:[(0,a.jsx)(h.default,{value:b,onChange:e=>w(e.target.value),className:A().codeInput,placeholder:"123456",maxLength:6}),(0,a.jsx)(p.Z,{type:"primary",onClick:Z,disabled:b.length<6,className:A().submitButton,children:"Verify Code"})]})]}),B=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{children:"Your Fediverse Account"}),(0,a.jsx)(h.default.Search,{addonBefore:"@",onInput:e=>{v(e.target.value),T(e.target.value)},value:x,placeholder:"youraccount@yourserver.com",status:!f&&x.length>0?"error":void 0,onSearch:L,enterButton:(0,a.jsx)(p.Z,{type:f?"primary":"default",disabled:!f||0===x.length,children:(0,a.jsx)(S,{})})})]});return(0,a.jsx)(c.Z,{spinning:d,children:(0,a.jsxs)(l.Z,{direction:"vertical",children:[N,C&&(0,a.jsx)(u.Z,{message:"Error",description:C,type:"error",showIcon:!0}),k?M:B,(0,a.jsx)(o.default,{ghost:!0,children:(0,a.jsx)(I,{header:"Learn more about using the Fediverse to authenticate with chat.",children:(0,a.jsx)("p",{children:"You can link your chat identity with your Fediverse identity. Next time you want to use this chat identity you can again go through the Fediverse authentication."})},"header")}),(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:"Note"}),": This is for authentication purposes only, and no personal information will be accessed or stored."]})]})})};var _=n(67633),N=n.n(_),C=n(14413),T=n(2906);let F=e=>{let{forceTabs:t}=e,n=(0,r.sJ)(C.L4),o=(0,r.sJ)(C.FI),d=(0,r.sJ)(C.db),c=(0,r.sJ)(C.g1);if(!d)return null;let{displayName:l}=d,{federation:u}=c,{enabled:h}=u,p=(0,a.jsxs)("span",{className:N().tabContent,children:[(0,a.jsx)("img",{className:N().icon,src:"/img/indieauth.png",alt:"IndieAuth"}),"IndieAuth"]}),y=(0,a.jsx)(b,{authenticated:n,displayName:l,accessToken:o}),f=(0,a.jsxs)("span",{className:N().tabContent,children:[(0,a.jsx)("img",{className:N().icon,src:"/img/fediverse-black.png",alt:"Fediverse auth"}),"FediAuth"]}),m=(0,a.jsx)(k,{authenticated:n,displayName:l,accessToken:o});return(0,a.jsx)(i.SV,{fallbackRender:e=>{let{error:t,resetErrorBoundary:n}=e;return(0,a.jsx)(T.A,{componentName:"AuthModal",message:t.message,retryFunction:n})},children:(0,a.jsx)("div",{children:(0,a.jsx)(s.Z,{defaultActiveKey:"1",items:[{label:p,key:"1",children:y},{label:f,key:"2",children:m}],type:"card",size:"small",renderTabBar:h||t?null:()=>null})})})}},88735:function(e,t,n){"use strict";n.d(t,{Kf:function(){return r},ME:function(){return i},ax:function(){return a},jv:function(){return s}});let a="https?://.*";function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["http:","https:"];try{let n=new URL(e);if(""===n.protocol||""===n.hostname||!t.includes(n.protocol))return!1}catch(e){return!1}return!0}function r(e,t){e.startsWith("@")&&(e=e.slice(1));let n=e.split(/:|@/),[a,s,r]=n;return a===t&&3===n.length&&!!a&&!!s&&!!r}function i(e){let t=e.replace(/^@+/,"");return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(t).toLowerCase())}},67633:function(e){e.exports={tabContent:"AuthModal_tabContent__sQX_a",icon:"AuthModal_icon__624lg"}},23772:function(e){e.exports={codeInputContainer:"FediAuthModal_codeInputContainer__LheQq",codeInput:"FediAuthModal_codeInput__TbAom",submitButton:"FediAuthModal_submitButton__n9SbC"}}}]); |