caplib
Version:
Credentialless Authentication Protocol Library for Web Applications
1 lines • 2.29 kB
Source Map (JSON)
{"version":3,"sources":["../../src/vue/components/CapAuth.ts"],"sourcesContent":["/**\n * Simple Vue adapter for CapAuth React component\n * This approach avoids Vue component complexity and just exports a function\n * that can be used to render the React component in a Vue application\n */\n\nimport { CapAuth as ReactCapAuth } from '../../react/components/CapAuth';\nimport { createRoot } from 'react-dom/client';\nimport { createElement } from 'react';\nimport type { User } from '../../types';\n\ninterface CapAuthOptions {\n config: any;\n onAuthenticated: (user: User) => void;\n onError?: (error: Error) => void;\n}\n\n/**\n * Mounts the CapAuth React component into a specified element\n */\nfunction mountCapAuth(element: HTMLElement, options: CapAuthOptions): () => void {\n const root = createRoot(element);\n\n root.render(\n createElement(ReactCapAuth, {\n config: options.config,\n onAuthenticated: options.onAuthenticated,\n onError: options.onError\n })\n );\n\n // Return a cleanup function\n return () => {\n root.unmount();\n };\n}\n\nexport default {\n /**\n * Mount CapAuth into an element\n */\n mount: mountCapAuth,\n\n /**\n * Vue directive (for use with v-capauth)\n */\n directive: {\n mounted(el: HTMLElement, binding: any) {\n const cleanup = mountCapAuth(el, binding.value);\n (el as any).__capauth_cleanup = cleanup;\n },\n unmounted(el: HTMLElement) {\n const cleanup = (el as any).__capauth_cleanup;\n if (typeof cleanup === 'function') {\n cleanup();\n }\n }\n }\n};"],"mappings":";;;;;AAOA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAY9B,SAAS,aAAa,SAAsB,SAAqC;AAC7E,QAAM,OAAO,WAAW,OAAO;AAE/B,OAAK;AAAA,IACD,cAAc,SAAc;AAAA,MACxB,QAAQ,QAAQ;AAAA,MAChB,iBAAiB,QAAQ;AAAA,MACzB,SAAS,QAAQ;AAAA,IACrB,CAAC;AAAA,EACL;AAGA,SAAO,MAAM;AACT,SAAK,QAAQ;AAAA,EACjB;AACJ;AAEA,IAAO,kBAAQ;AAAA;AAAA;AAAA;AAAA,EAIX,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,WAAW;AAAA,IACP,QAAQ,IAAiB,SAAc;AACnC,YAAM,UAAU,aAAa,IAAI,QAAQ,KAAK;AAC9C,MAAC,GAAW,oBAAoB;AAAA,IACpC;AAAA,IACA,UAAU,IAAiB;AACvB,YAAM,UAAW,GAAW;AAC5B,UAAI,OAAO,YAAY,YAAY;AAC/B,gBAAQ;AAAA,MACZ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}