Files
NianAIGC/out/_next/static/chunks/app/auth/admin-login/page-2dfbcccc4b553689.js
T
2026-09-02 17:02:02 +08:00

1 line
4.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[321,335,830,974],{63:(e,t,r)=>{"use strict";var n=r(7260);r.o(n,"usePathname")&&r.d(t,{usePathname:function(){return n.usePathname}}),r.o(n,"useRouter")&&r.d(t,{useRouter:function(){return n.useRouter}})},4577:(e,t,r)=>{"use strict";r.d(t,{BrowserAuthGuard:()=>c,BrowserAuthProvider:()=>s,ClientRedirect:()=>h,a:()=>l});var n=r(5155),a=r(2115),u=r(63),o=r(6660);let i=(0,a.createContext)(null);function s(e){let{children:t}=e,[r,u]=(0,a.useState)(null),[s,l]=(0,a.useState)("loading"),[c,h]=(0,a.useState)(null),d=(0,a.useCallback)(async e=>{try{let t=await (0,o.uK)(e);u(t),l("ready"),h(null)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;l("error"),h(e instanceof Error?e.message:"无法读取认证状态")}},[]);(0,a.useEffect)(()=>{let e=new AbortController;return d(e.signal),()=>e.abort()},[d]);let f=(0,a.useMemo)(()=>{var e,t;let n=(null==r?void 0:r.user)||null,a=null==(e=null==r?void 0:r.authRequired)||e,u=!a||(null==n?void 0:n.role)==="super_admin",o=u||(null==n?void 0:n.role)==="organization_admin";return{status:s,user:n,authMode:(null==r?void 0:r.authMode)||null,authRequired:a,authConfigured:null!=(t=null==r?void 0:r.authConfigured)&&t,isAdmin:o,isSuperAdmin:u,error:c,refresh:()=>d()}},[c,d,r,s]);return(0,n.jsx)(i.Provider,{value:f,children:t})}function l(){let e=(0,a.useContext)(i);if(!e)throw Error("useBrowserAuth must be used inside BrowserAuthProvider");return e}function c(e){let{children:t,role:r="user"}=e,i=l(),s=(0,u.usePathname)(),c=(0,u.useRouter)(),h="ready"===i.status&&i.authRequired&&!i.user;return((0,a.useEffect)(()=>{if(h){let e=(0,o.M6)(window.location,s||"/create");c.replace("/auth/login?next=".concat(encodeURIComponent(e)))}},[h,s,c]),"loading"===i.status||h)?(0,n.jsx)(d,{message:"正在确认登录状态…"}):"error"===i.status?(0,n.jsx)(d,{message:i.error||"无法读取认证状态",actionLabel:"重试",onAction:()=>void i.refresh()}):("admin"!==r||i.isAdmin)&&("super"!==r||i.isSuperAdmin)?(0,n.jsx)(n.Fragment,{children:t}):(0,n.jsx)(d,{message:"当前账号无权访问此页面。"})}function h(e){let{to:t,forwardNext:r=!1}=e;return(0,a.useEffect)(()=>{let e=r?new URLSearchParams(window.location.search).get("next"):null,n=e?"".concat(t,"?next=").concat(encodeURIComponent(e)):t;window.location.replace(n)},[r,t]),(0,n.jsx)(d,{message:"正在跳转…"})}function d(e){let{message:t,actionLabel:r,onAction:a}=e;return(0,n.jsxs)("section",{className:"panel",children:[(0,n.jsx)("p",{className:"muted",children:t}),r&&a?(0,n.jsx)("button",{className:"button",type:"button",onClick:a,children:r}):null]})}},6660:(e,t,r)=>{"use strict";async function n(e){let t=await fetch("/api/auth/me",{method:"GET",cache:"no-store",credentials:"same-origin",headers:{Accept:"application/json"},signal:e});if(!t.ok)throw Error("认证状态请求失败(".concat(t.status,")"));var r,n=await t.json();if(!o(n)||"boolean"!=typeof n.authenticated||"boolean"!=typeof n.authRequired||"boolean"!=typeof n.authConfigured)throw Error("认证状态响应格式无效");if(!n.authenticated){if(null!==n.authMode||null!==n.user)throw Error("认证状态响应格式无效");return{authenticated:!1,authRequired:n.authRequired,authConfigured:n.authConfigured,authMode:null,user:null}}if(!n.authConfigured||"user"!==n.authMode&&"admin"!==n.authMode||!(o(r=n.user)&&"string"==typeof r.id&&r.id.length>0&&"string"==typeof r.subject&&r.subject===r.id&&"string"==typeof r.displayName&&"string"==typeof r.clientId&&("user"===r.role||"organization_admin"===r.role||"super_admin"===r.role)&&"active"===r.status&&("super_admin"===r.role||"string"==typeof r.organizationId&&r.organizationId.length>0)&&Array.isArray(r.authorities)&&r.authorities.every(e=>"string"==typeof e)&&Array.isArray(r.scope)&&r.scope.every(e=>"string"==typeof e)))throw Error("认证用户响应格式无效");let a="user"===n.user.role?"user":"admin";if(n.authMode!==a)throw Error("认证用户响应格式无效");return{authenticated:!0,authRequired:n.authRequired,authConfigured:n.authConfigured,authMode:n.authMode,user:n.user}}function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";if(!e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))return t;try{let r="http://zhinian.local",n=new URL(e,r);if(n.origin!==r)return t;let a="".concat(n.pathname).concat(n.search).concat(n.hash);if(n.pathname.startsWith("/api/auth")||n.pathname.startsWith("/auth/login")||n.pathname.startsWith("/auth/admin-login"))return t;return a}catch(e){return t}}function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";return a("".concat(e.pathname).concat(e.search).concat(e.hash),t)}function o(e){return"object"==typeof e&&null!==e}r.d(t,{M6:()=>u,uK:()=>n,z3:()=>a})},9656:(e,t,r)=>{Promise.resolve().then(r.bind(r,4577))}},e=>{e.O(0,[441,255,358],()=>e(e.s=9656)),_N_E=e.O()}]);