@sbc-connect/nuxt-auth 0.0.0-test-ld-20260520212549

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/.env.example +35 -0
  2. package/CHANGELOG.md +495 -0
  3. package/LICENSE +28 -0
  4. package/README.md +58 -0
  5. package/app/app.config.ts +22 -0
  6. package/app/components/Connect/Account/Create/Name.vue +73 -0
  7. package/app/components/Connect/Account/Create/index.vue +148 -0
  8. package/app/components/Connect/Account/Existing/Alert.vue +10 -0
  9. package/app/components/Connect/Account/Existing/List/Item.vue +54 -0
  10. package/app/components/Connect/Account/Existing/List/index.vue +30 -0
  11. package/app/components/Connect/Header/AccountLabel.vue +39 -0
  12. package/app/components/Connect/Header/AccountOptionsMenu.vue +52 -0
  13. package/app/components/Connect/Header/Auth.vue +14 -0
  14. package/app/components/Connect/Header/AuthenticatedOptions.vue +13 -0
  15. package/app/components/Connect/Header/CreateAccountButton.vue +13 -0
  16. package/app/components/Connect/Header/LoginMenu.vue +27 -0
  17. package/app/components/Connect/Header/Notifications.vue +30 -0
  18. package/app/components/Connect/Header/UnauthenticatedOptions.vue +15 -0
  19. package/app/components/Connect/Layout/Auth.vue +19 -0
  20. package/app/components/Connect/Modal/InvalidIdp.vue +55 -0
  21. package/app/components/Connect/Modal/SessionExpired.vue +107 -0
  22. package/app/components/Connect/TermsOfUse/Content.vue +28 -0
  23. package/app/components/Connect/TermsOfUse/Form.vue +101 -0
  24. package/app/components/HelloWorld/Auth.vue +12 -0
  25. package/app/composables/useAuthApi.ts +156 -0
  26. package/app/composables/useConnectAccountFlowRedirect.ts +54 -0
  27. package/app/composables/useConnectAppConfig.ts +31 -0
  28. package/app/composables/useConnectAuth.ts +90 -0
  29. package/app/composables/useConnectAuthModals.ts +76 -0
  30. package/app/composables/useConnectHeaderOptions.ts +236 -0
  31. package/app/composables/useConnectLaunchDarkly.ts +250 -0
  32. package/app/coverage/app/app.config.ts.html +148 -0
  33. package/app/coverage/app/components/Connect/Account/Create/Name.vue.html +304 -0
  34. package/app/coverage/app/components/Connect/Account/Create/index.html +131 -0
  35. package/app/coverage/app/components/Connect/Account/Create/index.vue.html +487 -0
  36. package/app/coverage/app/components/Connect/Account/Existing/Alert.vue.html +115 -0
  37. package/app/coverage/app/components/Connect/Account/Existing/List/Item.vue.html +247 -0
  38. package/app/coverage/app/components/Connect/Account/Existing/List/index.html +131 -0
  39. package/app/coverage/app/components/Connect/Account/Existing/List/index.vue.html +175 -0
  40. package/app/coverage/app/components/Connect/Account/Existing/index.html +116 -0
  41. package/app/coverage/app/components/Connect/Header/AccountLabel.vue.html +202 -0
  42. package/app/coverage/app/components/Connect/Header/AccountOptionsMenu.vue.html +241 -0
  43. package/app/coverage/app/components/Connect/Header/Auth.vue.html +127 -0
  44. package/app/coverage/app/components/Connect/Header/AuthenticatedOptions.vue.html +124 -0
  45. package/app/coverage/app/components/Connect/Header/CreateAccountButton.vue.html +124 -0
  46. package/app/coverage/app/components/Connect/Header/LoginMenu.vue.html +166 -0
  47. package/app/coverage/app/components/Connect/Header/Notifications.vue.html +175 -0
  48. package/app/coverage/app/components/Connect/Header/UnauthenticatedOptions.vue.html +130 -0
  49. package/app/coverage/app/components/Connect/Header/index.html +221 -0
  50. package/app/coverage/app/components/Connect/Layout/Auth.vue.html +142 -0
  51. package/app/coverage/app/components/Connect/Layout/index.html +116 -0
  52. package/app/coverage/app/components/Connect/Modal/SessionExpired.vue.html +364 -0
  53. package/app/coverage/app/components/Connect/Modal/index.html +116 -0
  54. package/app/coverage/app/components/Connect/TermsOfUse/Content.vue.html +169 -0
  55. package/app/coverage/app/components/Connect/TermsOfUse/Form.vue.html +388 -0
  56. package/app/coverage/app/components/Connect/TermsOfUse/index.html +131 -0
  57. package/app/coverage/app/components/HelloWorld/Auth.vue.html +121 -0
  58. package/app/coverage/app/components/HelloWorld/index.html +116 -0
  59. package/app/coverage/app/composables/index.html +191 -0
  60. package/app/coverage/app/composables/useAuthApi.ts.html +547 -0
  61. package/app/coverage/app/composables/useConnectAccountFlowRedirect.ts.html +202 -0
  62. package/app/coverage/app/composables/useConnectAuth.ts.html +352 -0
  63. package/app/coverage/app/composables/useConnectAuthModals.ts.html +313 -0
  64. package/app/coverage/app/composables/useConnectHeaderOptions.ts.html +781 -0
  65. package/app/coverage/app/composables/useConnectLaunchDarkly.ts.html +820 -0
  66. package/app/coverage/app/enums/account-status.ts.html +112 -0
  67. package/app/coverage/app/enums/account-type.ts.html +103 -0
  68. package/app/coverage/app/enums/connect-access-type.ts.html +94 -0
  69. package/app/coverage/app/enums/connect-auth-storage-key.ts.html +94 -0
  70. package/app/coverage/app/enums/connect-idp-hint.ts.html +103 -0
  71. package/app/coverage/app/enums/connect-login-source.ts.html +103 -0
  72. package/app/coverage/app/enums/connect-payment-method.ts.html +94 -0
  73. package/app/coverage/app/enums/connect-product-code.ts.html +94 -0
  74. package/app/coverage/app/enums/connect-product-type.ts.html +94 -0
  75. package/app/coverage/app/enums/index.html +251 -0
  76. package/app/coverage/app/enums/user-settings-type.ts.html +100 -0
  77. package/app/coverage/app/index.html +116 -0
  78. package/app/coverage/app/interfaces/connect-account-address.ts.html +88 -0
  79. package/app/coverage/app/interfaces/connect-account.ts.html +154 -0
  80. package/app/coverage/app/interfaces/connect-auth-contact.ts.html +130 -0
  81. package/app/coverage/app/interfaces/connect-auth-profile.ts.html +157 -0
  82. package/app/coverage/app/interfaces/connect-auth-user.ts.html +115 -0
  83. package/app/coverage/app/interfaces/connect-terms-of-use.ts.html +103 -0
  84. package/app/coverage/app/interfaces/connect-user-settings.ts.html +115 -0
  85. package/app/coverage/app/interfaces/index.html +206 -0
  86. package/app/coverage/app/layouts/ConnectAuth.vue.html +100 -0
  87. package/app/coverage/app/layouts/index.html +116 -0
  88. package/app/coverage/app/middleware/01.setup-accounts.global.ts.html +124 -0
  89. package/app/coverage/app/middleware/02.keycloak-params.global.ts.html +130 -0
  90. package/app/coverage/app/middleware/03.allowed-idps.global.ts.html +145 -0
  91. package/app/coverage/app/middleware/connect-auth.ts.html +238 -0
  92. package/app/coverage/app/middleware/connect-login-page.ts.html +163 -0
  93. package/app/coverage/app/middleware/index.html +176 -0
  94. package/app/coverage/app/pages/auth/account/index.html +116 -0
  95. package/app/coverage/app/pages/auth/account/select.vue.html +424 -0
  96. package/app/coverage/app/pages/auth/index.html +146 -0
  97. package/app/coverage/app/pages/auth/login.vue.html +334 -0
  98. package/app/coverage/app/pages/auth/logout.vue.html +154 -0
  99. package/app/coverage/app/pages/auth/terms-of-use.vue.html +316 -0
  100. package/app/coverage/app/plugins/auth-api.ts.html +169 -0
  101. package/app/coverage/app/plugins/connect-auth.client.ts.html +382 -0
  102. package/app/coverage/app/plugins/index.html +131 -0
  103. package/app/coverage/app/stores/connect-account.ts.html +826 -0
  104. package/app/coverage/app/stores/index.html +116 -0
  105. package/app/coverage/app/types/connect-valid-idps.ts.html +100 -0
  106. package/app/coverage/app/types/index.html +116 -0
  107. package/app/coverage/app/utils/constants/index.html +131 -0
  108. package/app/coverage/app/utils/constants/index.ts.html +88 -0
  109. package/app/coverage/app/utils/constants/valid-idps.ts.html +106 -0
  110. package/app/coverage/app/utils/index.html +146 -0
  111. package/app/coverage/app/utils/index.ts.html +88 -0
  112. package/app/coverage/app/utils/resetPiniaStores.ts.html +184 -0
  113. package/app/coverage/app/utils/schemas/account.ts.html +313 -0
  114. package/app/coverage/app/utils/schemas/index.html +116 -0
  115. package/app/coverage/app/utils/setOnBeforeSessionExpired.ts.html +154 -0
  116. package/app/coverage/base.css +224 -0
  117. package/app/coverage/block-navigation.js +87 -0
  118. package/app/coverage/clover.xml +1939 -0
  119. package/app/coverage/coverage-final.json +63 -0
  120. package/app/coverage/favicon.png +0 -0
  121. package/app/coverage/index.html +431 -0
  122. package/app/coverage/prettify.css +1 -0
  123. package/app/coverage/prettify.js +2 -0
  124. package/app/coverage/sort-arrow-sprite.png +0 -0
  125. package/app/coverage/sorter.js +210 -0
  126. package/app/enums/account-status.ts +9 -0
  127. package/app/enums/account-type.ts +6 -0
  128. package/app/enums/connect-access-type.ts +3 -0
  129. package/app/enums/connect-auth-storage-key.ts +3 -0
  130. package/app/enums/connect-idp-hint.ts +6 -0
  131. package/app/enums/connect-login-source.ts +6 -0
  132. package/app/enums/connect-payment-method.ts +3 -0
  133. package/app/enums/connect-preset-type.ts +4 -0
  134. package/app/enums/connect-product-code.ts +3 -0
  135. package/app/enums/connect-product-type.ts +3 -0
  136. package/app/enums/user-settings-type.ts +5 -0
  137. package/app/interfaces/app-config-shapes.ts +40 -0
  138. package/app/interfaces/connect-account-address.ts +3 -0
  139. package/app/interfaces/connect-account.ts +23 -0
  140. package/app/interfaces/connect-auth-contact.ts +15 -0
  141. package/app/interfaces/connect-auth-profile.ts +24 -0
  142. package/app/interfaces/connect-auth-user.ts +10 -0
  143. package/app/interfaces/connect-terms-of-use.ts +6 -0
  144. package/app/interfaces/connect-user-settings.ts +10 -0
  145. package/app/layouts/ConnectAuth.vue +5 -0
  146. package/app/middleware/01.setup-accounts.global.ts +13 -0
  147. package/app/middleware/02.keycloak-params.global.ts +15 -0
  148. package/app/middleware/03.app-config-presets.global.ts +10 -0
  149. package/app/middleware/04.idp-enforcement.global.ts +30 -0
  150. package/app/middleware/connect-auth.ts +72 -0
  151. package/app/pages/auth/account/select.vue +121 -0
  152. package/app/pages/auth/login.vue +104 -0
  153. package/app/pages/auth/logout.vue +23 -0
  154. package/app/pages/auth/terms-of-use.vue +77 -0
  155. package/app/plugins/auth-api.ts +28 -0
  156. package/app/plugins/connect-auth.client.ts +112 -0
  157. package/app/stores/connect-account.ts +270 -0
  158. package/app/types/auth-app-config.d.ts +16 -0
  159. package/app/types/auth-page-meta.d.ts +8 -0
  160. package/app/types/connect-valid-idps.ts +5 -0
  161. package/app/utils/constants/index.ts +1 -0
  162. package/app/utils/constants/valid-idps.ts +7 -0
  163. package/app/utils/index.ts +1 -0
  164. package/app/utils/resetPiniaStores.ts +33 -0
  165. package/app/utils/schemas/account.ts +76 -0
  166. package/app/utils/setOnBeforeSessionExpired.ts +23 -0
  167. package/i18n/locales/en-CA.ts +114 -0
  168. package/i18n/locales/fr-CA.ts +1 -0
  169. package/nuxt.config.ts +84 -0
  170. package/package.json +44 -0
  171. package/playwright-report/index.html +85 -0
  172. package/public/img/BCReg_Generic_Login_image.jpg +0 -0
  173. package/test-results/.last-run.json +4 -0
  174. package/testMocks/auth/index.ts +2 -0
  175. package/testMocks/auth/profile/index.ts +9 -0
  176. package/testMocks/auth/profile/json/PUBLIC_USER.json +29 -0
  177. package/testMocks/auth/settings/index.ts +11 -0
  178. package/testMocks/auth/settings/json/PREMIUM.json +38 -0
  179. package/testMocks/auth/settings/json/SBC_STAFF.json +27 -0
  180. package/testMocks/auth/settings/json/STAFF.json +27 -0
  181. package/testMocks/mock-helpers.ts +15 -0
@@ -0,0 +1,121 @@
1
+ <script setup lang="ts">
2
+ definePageMeta({
3
+ layout: 'connect-auth',
4
+ alias: ['/auth/account/create'],
5
+ middleware: 'connect-auth'
6
+ })
7
+
8
+ const route = useRoute()
9
+ const rtc = useRuntimeConfig().public
10
+ const accountStore = useConnectAccountStore()
11
+ const { authUser } = useConnectAuth()
12
+ const { finalRedirect } = useConnectAccountFlowRedirect()
13
+ const { clearAccountState } = useConnectAccountStore()
14
+ const { isLoading } = storeToRefs(useConnectAccountStore())
15
+ const isAccountCreateRoute = computed(() => route.path.includes('create'))
16
+
17
+ const addNew = ref(false)
18
+ const pageTitle = computed(() =>
19
+ !addNew.value ? $t('connect.label.existingAccountFound') : $t('connect.label.sbcAccountCreation')
20
+ )
21
+
22
+ useHead({
23
+ title: pageTitle
24
+ })
25
+
26
+ async function selectAndRedirect(id: number) {
27
+ await accountStore.switchCurrentAccount(id)
28
+ finalRedirect(useRoute())
29
+ }
30
+
31
+ onBeforeMount(() => {
32
+ if ((accountStore.userAccounts.length === 0 && authUser.value.loginSource === ConnectLoginSource.BCSC)
33
+ || isAccountCreateRoute.value) {
34
+ addNew.value = true
35
+ }
36
+ })
37
+
38
+ const toggleCreateNewAccount = () => {
39
+ addNew.value = !addNew.value
40
+ clearAccountState()
41
+ }
42
+ </script>
43
+
44
+ <template>
45
+ <UContainer class="max-w-6xl">
46
+ <ConnectTransitionFade>
47
+ <div class="space-y-6 sm:space-y-10">
48
+ <h1>{{ !addNew ? $t('connect.label.existingAccountFound') : $t('connect.label.sbcAccountCreation') }}</h1>
49
+ <ConnectAccountExistingAlert v-if="!addNew" />
50
+ </div>
51
+ </ConnectTransitionFade>
52
+
53
+ <ConnectTransitionFade>
54
+ <ConnectAccountExistingList
55
+ v-if="addNew === false"
56
+ :accounts="accountStore.userAccounts"
57
+ @select="selectAndRedirect"
58
+ />
59
+
60
+ <ConnectAccountCreate
61
+ v-else
62
+ ref="account-create-form-ref"
63
+ />
64
+ </ConnectTransitionFade>
65
+
66
+ <!-- Select Account Actions -->
67
+ <div
68
+ v-if="!addNew"
69
+ class="flex justify-center"
70
+ data-testid="select-account-button-wrapper"
71
+ >
72
+ <UButton
73
+ v-if="authUser.loginSource === ConnectLoginSource.BCSC"
74
+ variant="outline"
75
+ :label="$t('connect.label.createNewAccount')"
76
+ icon="i-mdi-chevron-right"
77
+ trailing
78
+ size="xl"
79
+ class="w-full justify-center sm:w-min sm:justify-normal"
80
+ @click="toggleCreateNewAccount"
81
+ />
82
+ <UButton
83
+ v-else
84
+ variant="outline"
85
+ :label="$t('connect.label.createNewAccount')"
86
+ icon="i-mdi-chevron-right"
87
+ trailing
88
+ size="xl"
89
+ class="w-full justify-center sm:w-min sm:justify-normal"
90
+ external
91
+ :to="rtc.authWebUrl + 'setup-account'"
92
+ />
93
+ </div>
94
+
95
+ <!-- Create Account Actions -->
96
+ <div
97
+ v-if="addNew"
98
+ class="flex justify-end gap-x-3"
99
+ data-testid="create-account-button-wrapper"
100
+ >
101
+ <UButton
102
+ variant="outline"
103
+ :label="$t('connect.label.back')"
104
+ :disabled="isLoading"
105
+ trailing
106
+ size="xl"
107
+ class="w-full justify-center sm:w-min sm:justify-normal"
108
+ @click="toggleCreateNewAccount"
109
+ />
110
+ <UButton
111
+ :label="$t('connect.label.saveAndContinue')"
112
+ :loading="isLoading"
113
+ form="account-create-form"
114
+ class="w-full justify-center sm:w-min sm:justify-normal"
115
+ trailing
116
+ type="submit"
117
+ size="xl"
118
+ />
119
+ </div>
120
+ </UContainer>
121
+ </template>
@@ -0,0 +1,104 @@
1
+ <script setup lang="ts">
2
+ import loginImage from '#auth/public/img/BCReg_Generic_Login_image.jpg'
3
+
4
+ const { t } = useI18n()
5
+ const { login } = useConnectAuth()
6
+ const ac = useAppConfig().connect.login
7
+
8
+ useHead({
9
+ title: t('connect.page.login.title')
10
+ })
11
+
12
+ definePageMeta({
13
+ layout: 'connect-auth',
14
+ hideBreadcrumbs: true,
15
+ middleware: 'connect-auth',
16
+ connectLogin: true
17
+ })
18
+
19
+ const isSessionExpired = sessionStorage.getItem(ConnectAuthStorageKey.CONNECT_SESSION_EXPIRED)
20
+
21
+ const loginOptions = computed(() => {
22
+ const loginOptionsMap: Record<
23
+ ConnectValidIdpOption,
24
+ { label: string, icon: string, onClick: () => Promise<void> }
25
+ > = {
26
+ bcsc: {
27
+ label: t('connect.page.login.loginBCSC'),
28
+ icon: 'i-mdi-account-card-details-outline',
29
+ onClick: () => login(ConnectIdpHint.BCSC)
30
+ },
31
+ bceid: {
32
+ label: t('connect.page.login.loginBCEID'),
33
+ icon: 'i-mdi-two-factor-authentication',
34
+ onClick: () => login(ConnectIdpHint.BCEID)
35
+ },
36
+ idir: {
37
+ label: t('connect.page.login.loginIDIR'),
38
+ icon: 'i-mdi-account-group-outline',
39
+ onClick: () => login(ConnectIdpHint.IDIR)
40
+ }
41
+ }
42
+
43
+ return ac.idps.map(key => loginOptionsMap[key as keyof typeof loginOptionsMap])
44
+ })
45
+ </script>
46
+
47
+ <template>
48
+ <div class="flex grow flex-col items-center justify-center py-10">
49
+ <div class="flex flex-col items-center gap-4">
50
+ <!-- Alert message from app config -->
51
+ <UAlert
52
+ v-if="ac.alert"
53
+ class="max-w-[35em]"
54
+ color="warning"
55
+ variant="subtle"
56
+ data-testid="login-alert"
57
+ :title="ac.alert.title"
58
+ :description="ac.alert.message"
59
+ icon="i-mdi-check-circle"
60
+ :ui="{
61
+ icon: 'text-success',
62
+ }"
63
+ />
64
+ <h1>
65
+ {{ $t('connect.page.login.h1') }}
66
+ </h1>
67
+ <p class="max-w-[40rem] text-center">
68
+ {{ $t('connect.page.login.description') }}
69
+ </p>
70
+ <UAlert
71
+ v-if="isSessionExpired"
72
+ color="warning"
73
+ variant="subtle"
74
+ :title="$t('connect.page.login.sessionExpiredAlert.title')"
75
+ :description="$t('connect.page.login.sessionExpiredAlert.description')"
76
+ icon="i-mdi-alert"
77
+ />
78
+ <UCard
79
+ class="mt-[12px] max-w-md"
80
+ data-testid="login-card"
81
+ >
82
+ <img
83
+ :src="loginImage"
84
+ class="pb-4"
85
+ :alt="$t('connect.text.imageAltGenericLogin')"
86
+ >
87
+ <div class="space-y-4 pt-2.5">
88
+ <div
89
+ v-for="(option, i) in loginOptions"
90
+ :key="option.label"
91
+ class="flex flex-col items-center gap-1"
92
+ >
93
+ <UButton
94
+ :variant="i === 0 ? 'solid' : 'outline'"
95
+ block
96
+ class="py-2.5"
97
+ v-bind="option"
98
+ />
99
+ </div>
100
+ </div>
101
+ </UCard>
102
+ </div>
103
+ </div>
104
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ const route = useRoute()
3
+ const rtc = useRuntimeConfig().public
4
+ const ac = useAppConfig().connect
5
+ const { locale } = useI18n()
6
+ const { logout } = useConnectAuth()
7
+
8
+ const redirectUrl = computed(() => {
9
+ const urlReturn = route.query.return
10
+ const url = urlReturn !== undefined
11
+ ? urlReturn as string
12
+ : `${rtc.baseUrl}${locale.value}${ac.logout.redirect}`
13
+ return url
14
+ })
15
+
16
+ onMounted(async () => {
17
+ await logout(redirectUrl.value)
18
+ })
19
+ </script>
20
+
21
+ <template>
22
+ <ConnectSpinner fullscreen />
23
+ </template>
@@ -0,0 +1,77 @@
1
+ <script setup lang="ts">
2
+ import { ConnectTermsOfUseContent, ConnectTermsOfUseForm } from '#components'
3
+
4
+ const { t } = useI18n()
5
+ const authApi = useAuthApi()
6
+ const { finalRedirect } = useConnectAccountFlowRedirect()
7
+
8
+ definePageMeta({
9
+ layout: 'connect-auth',
10
+ hideBreadcrumbs: true,
11
+ middleware: 'connect-auth',
12
+ connectTosPage: true
13
+ })
14
+
15
+ useHead({
16
+ title: t('connect.page.termsOfUse.title')
17
+ })
18
+
19
+ const { data, status } = await authApi.getTermsOfUse()
20
+ const { patchTermsOfUse, isLoading } = authApi.usePatchTermsOfUse()
21
+
22
+ const formRef = useTemplateRef<InstanceType<typeof ConnectTermsOfUseForm>>('form-ref')
23
+ const contentRef = useTemplateRef<InstanceType<typeof ConnectTermsOfUseContent>>('content-ref')
24
+
25
+ // track if user has scrolled to bottom of page
26
+ const { bottom: tosBottom } = useElementBounding(contentRef)
27
+ const { top: formTop } = useElementBounding(formRef)
28
+ const hasReachedBottom = computed(() => formTop.value >= tosBottom.value)
29
+
30
+ const disableButtons = computed<boolean>(() => {
31
+ return isLoading.value || status.value === 'pending' || status.value === 'error' || !data.value?.content
32
+ })
33
+
34
+ // TODO: - FUTURE - add help/contact info to alert?
35
+ </script>
36
+
37
+ <template>
38
+ <UContainer
39
+ class="max-w-6xl relative grow flex flex-col"
40
+ >
41
+ <h1 class="sticky top-0 w-full border-b border-line bg-shade pb-2 pt-4 text-center z-10 inset-x-0">
42
+ {{ $t('connect.page.termsOfUse.h1') }}
43
+ </h1>
44
+
45
+ <div class="relative grow flex flex-col justify-center">
46
+ <ConnectSpinner v-if="status === 'pending'" />
47
+
48
+ <UAlert
49
+ v-else-if="status === 'error'"
50
+ icon="i-mdi-alert"
51
+ :title="$t('connect.text.alertUnableToLoadTermsOfUse')"
52
+ color="error"
53
+ variant="subtle"
54
+ :close-button="null"
55
+ :ui="{ title: 'text-base' }"
56
+ />
57
+
58
+ <ConnectTermsOfUseContent
59
+ v-else
60
+ ref="content-ref"
61
+ :content="data?.content"
62
+ />
63
+ </div>
64
+
65
+ <ConnectTermsOfUseForm
66
+ ref="form-ref"
67
+ :disable-buttons="disableButtons"
68
+ :has-reached-bottom="hasReachedBottom"
69
+ :loading="isLoading"
70
+ @submit="patchTermsOfUse({
71
+ accepted: true,
72
+ version: data!.versionId,
73
+ successCb: async () => await finalRedirect(useRoute(), true),
74
+ })"
75
+ />
76
+ </UContainer>
77
+ </template>
@@ -0,0 +1,28 @@
1
+ export default defineNuxtPlugin((nuxtApp) => {
2
+ const rtc = nuxtApp.$config.public
3
+ const authApiUrl = rtc.authApiUrl + rtc.authApiVersion
4
+ const appName = rtc.appName
5
+ const xApiKey = rtc.xApiKey
6
+
7
+ const api = $fetch.create({
8
+ baseURL: authApiUrl,
9
+ async onRequest({ options }) {
10
+ const auth = useConnectAuth()
11
+ const accountStore = useConnectAccountStore()
12
+
13
+ const token = await auth.getToken()
14
+ const accountId = accountStore.currentAccount.id
15
+
16
+ options.headers.set('Authorization', `Bearer ${token}`)
17
+ options.headers.set('App-Name', appName)
18
+ options.headers.set('X-Apikey', xApiKey)
19
+ options.headers.set('Account-Id', String(accountId))
20
+ }
21
+ })
22
+
23
+ return {
24
+ provide: {
25
+ authApi: api
26
+ }
27
+ }
28
+ })
@@ -0,0 +1,112 @@
1
+ import Keycloak from 'keycloak-js'
2
+ import { ConnectModalSessionExpired } from '#components'
3
+
4
+ export default defineNuxtPlugin(async () => {
5
+ const rtc = useRuntimeConfig().public
6
+
7
+ // define new keycloak
8
+ const keycloak = new Keycloak({
9
+ url: rtc.idpUrl,
10
+ realm: rtc.idpRealm,
11
+ clientId: rtc.idpClientid
12
+ })
13
+
14
+ const tokenRefreshInterval = rtc.tokenRefreshInterval ? Number(rtc.tokenRefreshInterval) : 30000
15
+ const tokenMinValidity = rtc.tokenMinValidity ? Number(rtc.tokenMinValidity) / 1000 : 120
16
+ const sessionInactivityTimeout = rtc.sessionInactivityTimeout ? Number(rtc.sessionInactivityTimeout) : 1800000
17
+
18
+ // Logout via Keycloak, redirecting to the login page with a return param preserving the user's current URL.
19
+ // The return value is double-encoded so it survives the Keycloak redirect decode
20
+ // without the original query params bleeding into the login page's query string.
21
+ function logoutWithReturn(kc: Keycloak) {
22
+ const localePath = useLocalePath()
23
+ const route = useRoute()
24
+ const loginPath = localePath('/auth/login')
25
+ const currentUrl = `${window.location.origin}${route.fullPath}`
26
+ const returnUrl = encodeURIComponent(encodeURIComponent(currentUrl))
27
+ const redirectUri = `${window.location.origin}${loginPath}?return=${returnUrl}`
28
+ kc.logout({ redirectUri })
29
+ }
30
+
31
+ try {
32
+ // default behaviour when keycloak session expires
33
+ // try to update token - log out if token update fails
34
+ // callbacks must be registered before 'init'
35
+ // https://www.keycloak.org/securing-apps/javascript-adapter#_callback_events
36
+ keycloak.onTokenExpired = async () => {
37
+ try {
38
+ console.info('[Auth] Token expired, refreshing token...')
39
+ await keycloak.updateToken(tokenMinValidity)
40
+ console.info('[Auth] Token refreshed.')
41
+ } catch (error) {
42
+ console.error('[Auth] Failed to refresh token on expiration; logging out.', error)
43
+ logoutWithReturn(keycloak)
44
+ }
45
+ }
46
+
47
+ // init keycloak instance
48
+ await keycloak.init({
49
+ onLoad: 'check-sso',
50
+ responseMode: 'query',
51
+ pkceMethod: 'S256'
52
+ })
53
+ } catch (error) {
54
+ console.error('[Auth] Failed to initialize Keycloak adapter: ', error)
55
+ }
56
+
57
+ const { idle } = useIdle(sessionInactivityTimeout)
58
+
59
+ // executed when user is authenticated and idle = true
60
+ async function sessionExpired() {
61
+ const overlay = useOverlay()
62
+ const modal = overlay.create(ConnectModalSessionExpired)
63
+ modal.open()
64
+ }
65
+
66
+ // refresh token if expiring within <tokenMinValidity> - checks every <tokenRefreshInterval>
67
+ function scheduleRefreshToken() {
68
+ console.info('[Auth] Verifying token validity.')
69
+
70
+ setTimeout(async () => {
71
+ if (keycloak.isTokenExpired(tokenMinValidity)) {
72
+ console.info('[Auth] Token set to expire soon. Refreshing token...')
73
+ try {
74
+ await keycloak.updateToken(tokenMinValidity)
75
+ console.info('[Auth] Token refreshed.')
76
+ } catch (error) {
77
+ console.error('[Auth] Failed to refresh token; logging out.', error)
78
+ logoutWithReturn(keycloak)
79
+ }
80
+ }
81
+
82
+ scheduleRefreshToken()
83
+ }, tokenRefreshInterval)
84
+ }
85
+
86
+ // Watch for changes in authentication and idle state
87
+ // When the user is authenticated and not idle, start the refresh schedule
88
+ // Execute session expiry handling if user authenticated and inactive
89
+ watch(
90
+ [() => keycloak.authenticated, () => idle.value],
91
+ async ([isAuth, isIdle]) => {
92
+ if (isAuth) {
93
+ sessionStorage.removeItem(ConnectAuthStorageKey.CONNECT_SESSION_EXPIRED)
94
+ if (!isIdle) {
95
+ console.info('[Auth] Starting token refresh schedule.')
96
+ scheduleRefreshToken()
97
+ } else {
98
+ console.warn('[Auth] User session expired due to inactivity. Starting session expiry process.')
99
+ await sessionExpired()
100
+ }
101
+ }
102
+ },
103
+ { immediate: true }
104
+ )
105
+
106
+ return {
107
+ provide: {
108
+ // provide global auth instance
109
+ connectAuth: keycloak
110
+ }
111
+ }
112
+ })