|
9 | 9 | >
|
10 | 10 | <div
|
11 | 11 | v-if="chatWidget.isOpenChat || chatWidget.isClosing"
|
12 |
| - class="fixed right-0 z-[55] border surface-ground surface-border transition-transform ease-in-out max-md:w-full max-md:h-full max-md:top-0 max-md:right-0" |
13 |
| - :class="chatClass" |
| 12 | + :class="[ |
| 13 | + ...chatClass, |
| 14 | + { 'pointer-events-none': showAuthOverlay }, |
| 15 | + 'fixed right-0 z-[55] border surface-ground surface-border transition-transform ease-in-out max-md:w-full max-md:h-full max-md:top-0 max-md:right-0' |
| 16 | + ]" |
14 | 17 | @transitionend="onTransitionEnd"
|
15 | 18 | >
|
16 | 19 | <div class="h-full flex flex-col">
|
|
32 | 35 | </div>
|
33 | 36 | </div>
|
34 | 37 | </Transition>
|
| 38 | + |
| 39 | + <!-- Auth overlay - only show for basic auth --> |
| 40 | + <Transition |
| 41 | + enter-active-class="transition-all duration-300 ease-out" |
| 42 | + enter-from-class="opacity-0" |
| 43 | + enter-to-class="opacity-100" |
| 44 | + leave-active-class="transition-all duration-300 ease-in" |
| 45 | + leave-from-class="opacity-100" |
| 46 | + leave-to-class="opacity-0" |
| 47 | + > |
| 48 | + <div v-if="showAuthOverlay && chatWidget.authMode === 'basic'" |
| 49 | + class="fixed inset-0 z-[60] bg-black/50 flex items-center justify-center"> |
| 50 | + <BasicAuthWindow :onSubmit="handleAuthSubmit" /> |
| 51 | + </div> |
| 52 | + </Transition> |
35 | 53 | </template>
|
36 | 54 |
|
37 | 55 | <script setup>
|
38 |
| - import { computed, inject } from 'vue' |
| 56 | + import { computed, inject, ref } from 'vue' |
39 | 57 | import ChatHeader from './chat-header.vue'
|
40 | 58 | import ChatBody from './chat-body.vue'
|
41 | 59 | import ChatFooter from './chat-footer.vue'
|
| 60 | + import BasicAuthWindow from '../BasicAuthWindow.vue' |
42 | 61 | import { useAzionCopilot } from '../../composables/useAzionCopilot'
|
| 62 | + import { AuthService } from '../../services/auth' |
| 63 | + import { CONSTANTS } from '../../core' |
43 | 64 |
|
44 | 65 | const chatWidget = inject('chatWidget')
|
| 66 | + const showAuthOverlay = ref(false) |
45 | 67 |
|
46 | 68 | defineOptions({ name: 'layout-chat' })
|
47 | 69 |
|
48 |
| - const { messages, sendMessage, cancelMessage, resetChat, isProcessingRequest, sendFeedback } = |
| 70 | + const { messages, sendMessage, cancelMessage, resetChat, isProcessingRequest, sendFeedback, copilot } = |
49 | 71 | useAzionCopilot({ server: chatWidget.serverUrl })
|
50 | 72 |
|
| 73 | + copilot.on(CONSTANTS.EVENTS.AUTH_REQUIRED, () => { |
| 74 | + console.log(chatWidget) |
| 75 | + if (chatWidget.authMode === 'basic') { |
| 76 | + showAuthOverlay.value = true |
| 77 | + } |
| 78 | + }) |
| 79 | +
|
| 80 | + const handleAuthSubmit = async (password) => { |
| 81 | + const authService = new AuthService({ |
| 82 | + authMode: 'basic', |
| 83 | + copilotBackend: chatWidget.serverUrl.url |
| 84 | + }) |
| 85 | + |
| 86 | + const result = await authService.fetchBasicAuth(password) |
| 87 | + if (result.token) { |
| 88 | + copilot.setAuthToken(result.token) |
| 89 | + showAuthOverlay.value = false |
| 90 | + } |
| 91 | + } |
| 92 | +
|
51 | 93 | const closeChat = () => {
|
52 | 94 | chatWidget.isClosing = true
|
53 | 95 | }
|
|
0 commit comments