@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.
- package/.env.example +35 -0
- package/CHANGELOG.md +495 -0
- package/LICENSE +28 -0
- package/README.md +58 -0
- package/app/app.config.ts +22 -0
- package/app/components/Connect/Account/Create/Name.vue +73 -0
- package/app/components/Connect/Account/Create/index.vue +148 -0
- package/app/components/Connect/Account/Existing/Alert.vue +10 -0
- package/app/components/Connect/Account/Existing/List/Item.vue +54 -0
- package/app/components/Connect/Account/Existing/List/index.vue +30 -0
- package/app/components/Connect/Header/AccountLabel.vue +39 -0
- package/app/components/Connect/Header/AccountOptionsMenu.vue +52 -0
- package/app/components/Connect/Header/Auth.vue +14 -0
- package/app/components/Connect/Header/AuthenticatedOptions.vue +13 -0
- package/app/components/Connect/Header/CreateAccountButton.vue +13 -0
- package/app/components/Connect/Header/LoginMenu.vue +27 -0
- package/app/components/Connect/Header/Notifications.vue +30 -0
- package/app/components/Connect/Header/UnauthenticatedOptions.vue +15 -0
- package/app/components/Connect/Layout/Auth.vue +19 -0
- package/app/components/Connect/Modal/InvalidIdp.vue +55 -0
- package/app/components/Connect/Modal/SessionExpired.vue +107 -0
- package/app/components/Connect/TermsOfUse/Content.vue +28 -0
- package/app/components/Connect/TermsOfUse/Form.vue +101 -0
- package/app/components/HelloWorld/Auth.vue +12 -0
- package/app/composables/useAuthApi.ts +156 -0
- package/app/composables/useConnectAccountFlowRedirect.ts +54 -0
- package/app/composables/useConnectAppConfig.ts +31 -0
- package/app/composables/useConnectAuth.ts +90 -0
- package/app/composables/useConnectAuthModals.ts +76 -0
- package/app/composables/useConnectHeaderOptions.ts +236 -0
- package/app/composables/useConnectLaunchDarkly.ts +250 -0
- package/app/coverage/app/app.config.ts.html +148 -0
- package/app/coverage/app/components/Connect/Account/Create/Name.vue.html +304 -0
- package/app/coverage/app/components/Connect/Account/Create/index.html +131 -0
- package/app/coverage/app/components/Connect/Account/Create/index.vue.html +487 -0
- package/app/coverage/app/components/Connect/Account/Existing/Alert.vue.html +115 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/Item.vue.html +247 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/index.html +131 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/index.vue.html +175 -0
- package/app/coverage/app/components/Connect/Account/Existing/index.html +116 -0
- package/app/coverage/app/components/Connect/Header/AccountLabel.vue.html +202 -0
- package/app/coverage/app/components/Connect/Header/AccountOptionsMenu.vue.html +241 -0
- package/app/coverage/app/components/Connect/Header/Auth.vue.html +127 -0
- package/app/coverage/app/components/Connect/Header/AuthenticatedOptions.vue.html +124 -0
- package/app/coverage/app/components/Connect/Header/CreateAccountButton.vue.html +124 -0
- package/app/coverage/app/components/Connect/Header/LoginMenu.vue.html +166 -0
- package/app/coverage/app/components/Connect/Header/Notifications.vue.html +175 -0
- package/app/coverage/app/components/Connect/Header/UnauthenticatedOptions.vue.html +130 -0
- package/app/coverage/app/components/Connect/Header/index.html +221 -0
- package/app/coverage/app/components/Connect/Layout/Auth.vue.html +142 -0
- package/app/coverage/app/components/Connect/Layout/index.html +116 -0
- package/app/coverage/app/components/Connect/Modal/SessionExpired.vue.html +364 -0
- package/app/coverage/app/components/Connect/Modal/index.html +116 -0
- package/app/coverage/app/components/Connect/TermsOfUse/Content.vue.html +169 -0
- package/app/coverage/app/components/Connect/TermsOfUse/Form.vue.html +388 -0
- package/app/coverage/app/components/Connect/TermsOfUse/index.html +131 -0
- package/app/coverage/app/components/HelloWorld/Auth.vue.html +121 -0
- package/app/coverage/app/components/HelloWorld/index.html +116 -0
- package/app/coverage/app/composables/index.html +191 -0
- package/app/coverage/app/composables/useAuthApi.ts.html +547 -0
- package/app/coverage/app/composables/useConnectAccountFlowRedirect.ts.html +202 -0
- package/app/coverage/app/composables/useConnectAuth.ts.html +352 -0
- package/app/coverage/app/composables/useConnectAuthModals.ts.html +313 -0
- package/app/coverage/app/composables/useConnectHeaderOptions.ts.html +781 -0
- package/app/coverage/app/composables/useConnectLaunchDarkly.ts.html +820 -0
- package/app/coverage/app/enums/account-status.ts.html +112 -0
- package/app/coverage/app/enums/account-type.ts.html +103 -0
- package/app/coverage/app/enums/connect-access-type.ts.html +94 -0
- package/app/coverage/app/enums/connect-auth-storage-key.ts.html +94 -0
- package/app/coverage/app/enums/connect-idp-hint.ts.html +103 -0
- package/app/coverage/app/enums/connect-login-source.ts.html +103 -0
- package/app/coverage/app/enums/connect-payment-method.ts.html +94 -0
- package/app/coverage/app/enums/connect-product-code.ts.html +94 -0
- package/app/coverage/app/enums/connect-product-type.ts.html +94 -0
- package/app/coverage/app/enums/index.html +251 -0
- package/app/coverage/app/enums/user-settings-type.ts.html +100 -0
- package/app/coverage/app/index.html +116 -0
- package/app/coverage/app/interfaces/connect-account-address.ts.html +88 -0
- package/app/coverage/app/interfaces/connect-account.ts.html +154 -0
- package/app/coverage/app/interfaces/connect-auth-contact.ts.html +130 -0
- package/app/coverage/app/interfaces/connect-auth-profile.ts.html +157 -0
- package/app/coverage/app/interfaces/connect-auth-user.ts.html +115 -0
- package/app/coverage/app/interfaces/connect-terms-of-use.ts.html +103 -0
- package/app/coverage/app/interfaces/connect-user-settings.ts.html +115 -0
- package/app/coverage/app/interfaces/index.html +206 -0
- package/app/coverage/app/layouts/ConnectAuth.vue.html +100 -0
- package/app/coverage/app/layouts/index.html +116 -0
- package/app/coverage/app/middleware/01.setup-accounts.global.ts.html +124 -0
- package/app/coverage/app/middleware/02.keycloak-params.global.ts.html +130 -0
- package/app/coverage/app/middleware/03.allowed-idps.global.ts.html +145 -0
- package/app/coverage/app/middleware/connect-auth.ts.html +238 -0
- package/app/coverage/app/middleware/connect-login-page.ts.html +163 -0
- package/app/coverage/app/middleware/index.html +176 -0
- package/app/coverage/app/pages/auth/account/index.html +116 -0
- package/app/coverage/app/pages/auth/account/select.vue.html +424 -0
- package/app/coverage/app/pages/auth/index.html +146 -0
- package/app/coverage/app/pages/auth/login.vue.html +334 -0
- package/app/coverage/app/pages/auth/logout.vue.html +154 -0
- package/app/coverage/app/pages/auth/terms-of-use.vue.html +316 -0
- package/app/coverage/app/plugins/auth-api.ts.html +169 -0
- package/app/coverage/app/plugins/connect-auth.client.ts.html +382 -0
- package/app/coverage/app/plugins/index.html +131 -0
- package/app/coverage/app/stores/connect-account.ts.html +826 -0
- package/app/coverage/app/stores/index.html +116 -0
- package/app/coverage/app/types/connect-valid-idps.ts.html +100 -0
- package/app/coverage/app/types/index.html +116 -0
- package/app/coverage/app/utils/constants/index.html +131 -0
- package/app/coverage/app/utils/constants/index.ts.html +88 -0
- package/app/coverage/app/utils/constants/valid-idps.ts.html +106 -0
- package/app/coverage/app/utils/index.html +146 -0
- package/app/coverage/app/utils/index.ts.html +88 -0
- package/app/coverage/app/utils/resetPiniaStores.ts.html +184 -0
- package/app/coverage/app/utils/schemas/account.ts.html +313 -0
- package/app/coverage/app/utils/schemas/index.html +116 -0
- package/app/coverage/app/utils/setOnBeforeSessionExpired.ts.html +154 -0
- package/app/coverage/base.css +224 -0
- package/app/coverage/block-navigation.js +87 -0
- package/app/coverage/clover.xml +1939 -0
- package/app/coverage/coverage-final.json +63 -0
- package/app/coverage/favicon.png +0 -0
- package/app/coverage/index.html +431 -0
- package/app/coverage/prettify.css +1 -0
- package/app/coverage/prettify.js +2 -0
- package/app/coverage/sort-arrow-sprite.png +0 -0
- package/app/coverage/sorter.js +210 -0
- package/app/enums/account-status.ts +9 -0
- package/app/enums/account-type.ts +6 -0
- package/app/enums/connect-access-type.ts +3 -0
- package/app/enums/connect-auth-storage-key.ts +3 -0
- package/app/enums/connect-idp-hint.ts +6 -0
- package/app/enums/connect-login-source.ts +6 -0
- package/app/enums/connect-payment-method.ts +3 -0
- package/app/enums/connect-preset-type.ts +4 -0
- package/app/enums/connect-product-code.ts +3 -0
- package/app/enums/connect-product-type.ts +3 -0
- package/app/enums/user-settings-type.ts +5 -0
- package/app/interfaces/app-config-shapes.ts +40 -0
- package/app/interfaces/connect-account-address.ts +3 -0
- package/app/interfaces/connect-account.ts +23 -0
- package/app/interfaces/connect-auth-contact.ts +15 -0
- package/app/interfaces/connect-auth-profile.ts +24 -0
- package/app/interfaces/connect-auth-user.ts +10 -0
- package/app/interfaces/connect-terms-of-use.ts +6 -0
- package/app/interfaces/connect-user-settings.ts +10 -0
- package/app/layouts/ConnectAuth.vue +5 -0
- package/app/middleware/01.setup-accounts.global.ts +13 -0
- package/app/middleware/02.keycloak-params.global.ts +15 -0
- package/app/middleware/03.app-config-presets.global.ts +10 -0
- package/app/middleware/04.idp-enforcement.global.ts +30 -0
- package/app/middleware/connect-auth.ts +72 -0
- package/app/pages/auth/account/select.vue +121 -0
- package/app/pages/auth/login.vue +104 -0
- package/app/pages/auth/logout.vue +23 -0
- package/app/pages/auth/terms-of-use.vue +77 -0
- package/app/plugins/auth-api.ts +28 -0
- package/app/plugins/connect-auth.client.ts +112 -0
- package/app/stores/connect-account.ts +270 -0
- package/app/types/auth-app-config.d.ts +16 -0
- package/app/types/auth-page-meta.d.ts +8 -0
- package/app/types/connect-valid-idps.ts +5 -0
- package/app/utils/constants/index.ts +1 -0
- package/app/utils/constants/valid-idps.ts +7 -0
- package/app/utils/index.ts +1 -0
- package/app/utils/resetPiniaStores.ts +33 -0
- package/app/utils/schemas/account.ts +76 -0
- package/app/utils/setOnBeforeSessionExpired.ts +23 -0
- package/i18n/locales/en-CA.ts +114 -0
- package/i18n/locales/fr-CA.ts +1 -0
- package/nuxt.config.ts +84 -0
- package/package.json +44 -0
- package/playwright-report/index.html +85 -0
- package/public/img/BCReg_Generic_Login_image.jpg +0 -0
- package/test-results/.last-run.json +4 -0
- package/testMocks/auth/index.ts +2 -0
- package/testMocks/auth/profile/index.ts +9 -0
- package/testMocks/auth/profile/json/PUBLIC_USER.json +29 -0
- package/testMocks/auth/settings/index.ts +11 -0
- package/testMocks/auth/settings/json/PREMIUM.json +38 -0
- package/testMocks/auth/settings/json/SBC_STAFF.json +27 -0
- package/testMocks/auth/settings/json/STAFF.json +27 -0
- package/testMocks/mock-helpers.ts +15 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const isSmallScreen = useMediaQuery('(max-width: 640px)')
|
|
3
|
+
const rtc = useRuntimeConfig().public
|
|
4
|
+
const modalTimeout = rtc.sessionModalTimeout ? Number(rtc.sessionModalTimeout) : 120000
|
|
5
|
+
const { t } = useI18n()
|
|
6
|
+
const route = useRoute()
|
|
7
|
+
const localePath = useLocalePath()
|
|
8
|
+
|
|
9
|
+
const emit = defineEmits<{ close: [] }>()
|
|
10
|
+
|
|
11
|
+
const timeRemaining = ref(toValue((modalTimeout) / 1000))
|
|
12
|
+
|
|
13
|
+
// Capture the user's current location when the modal opens, before any potential URL changes
|
|
14
|
+
const capturedUrl = `${window.location.origin}${route.fullPath}`
|
|
15
|
+
|
|
16
|
+
/** Build a login page URL with a return param preserving the user's current location.
|
|
17
|
+
* The return value is double-encoded so it survives the Keycloak redirect decode
|
|
18
|
+
* without the original query params bleeding into the login page's query string.
|
|
19
|
+
*/
|
|
20
|
+
function getSessionExpiredRedirect(): string {
|
|
21
|
+
const loginPath = localePath('/auth/login')
|
|
22
|
+
const returnUrl = encodeURIComponent(encodeURIComponent(capturedUrl))
|
|
23
|
+
return `${window.location.origin}${loginPath}?return=${returnUrl}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const intervalId = setInterval(async () => {
|
|
27
|
+
const value = timeRemaining.value - 1
|
|
28
|
+
timeRemaining.value = value < 0 ? 0 : value
|
|
29
|
+
|
|
30
|
+
if (value === 0) {
|
|
31
|
+
if (route.meta.onBeforeSessionExpired) {
|
|
32
|
+
await route.meta.onBeforeSessionExpired()
|
|
33
|
+
}
|
|
34
|
+
sessionStorage.setItem(ConnectAuthStorageKey.CONNECT_SESSION_EXPIRED, 'true')
|
|
35
|
+
await useConnectAuth().logout(getSessionExpiredRedirect())
|
|
36
|
+
}
|
|
37
|
+
}, 1000)
|
|
38
|
+
|
|
39
|
+
const ariaCountdownText = computed(() => {
|
|
40
|
+
if (timeRemaining.value === 30) { // trigger aria alert when 30 seconds remain
|
|
41
|
+
return t('connect.sessionExpiry.content', { count: timeRemaining.value })
|
|
42
|
+
} else if (timeRemaining.value === 2) { // trigger aria alert when session expires
|
|
43
|
+
return t('connect.sessionExpiry.sessionExpired')
|
|
44
|
+
} else {
|
|
45
|
+
return ''
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
function closeModal() {
|
|
50
|
+
clearInterval(intervalId)
|
|
51
|
+
emit('close')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
// allow any keypress to close the modal
|
|
56
|
+
window.addEventListener('keydown', closeModal)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
onUnmounted(() => {
|
|
60
|
+
// cleanup
|
|
61
|
+
window.removeEventListener('keydown', closeModal)
|
|
62
|
+
})
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<template>
|
|
66
|
+
<UModal
|
|
67
|
+
id="session-expired-dialog"
|
|
68
|
+
overlay
|
|
69
|
+
:title="$t('connect.sessionExpiry.title')"
|
|
70
|
+
:description="$t('connect.sessionExpiry.content', { count: timeRemaining })"
|
|
71
|
+
@after:leave="closeModal"
|
|
72
|
+
>
|
|
73
|
+
<template #content>
|
|
74
|
+
<div class="p-10 flex flex-col gap-6">
|
|
75
|
+
<div role="alert">
|
|
76
|
+
<h2
|
|
77
|
+
id="session-expired-dialog-title"
|
|
78
|
+
class="text-xl font-bold text-neutral-highlighted"
|
|
79
|
+
>
|
|
80
|
+
{{ $t('connect.sessionExpiry.title') }}
|
|
81
|
+
</h2>
|
|
82
|
+
</div>
|
|
83
|
+
<div>
|
|
84
|
+
<ConnectI18nHelper
|
|
85
|
+
id="session-expired-dialog-description"
|
|
86
|
+
translation-path="connect.sessionExpiry.content"
|
|
87
|
+
:count="timeRemaining"
|
|
88
|
+
/>
|
|
89
|
+
|
|
90
|
+
<div role="alert">
|
|
91
|
+
<span class="sr-only">{{ ariaCountdownText }}</span>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="flex flex-wrap items-center justify-center gap-4">
|
|
95
|
+
<UButton
|
|
96
|
+
:block="isSmallScreen"
|
|
97
|
+
:label="$t('connect.sessionExpiry.continueBtn.main')"
|
|
98
|
+
:aria-label="$t('connect.sessionExpiry.continueBtn.aria')"
|
|
99
|
+
size="xl"
|
|
100
|
+
class="font-bold"
|
|
101
|
+
@click="closeModal"
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</template>
|
|
106
|
+
</UModal>
|
|
107
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
content?: string
|
|
4
|
+
}>()
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<div
|
|
9
|
+
v-sanitize="content"
|
|
10
|
+
class="tos-content max-w-full wrap-break-word space-y-6 *:space-y-4"
|
|
11
|
+
/>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<style scoped>
|
|
15
|
+
@reference "#connect-theme";
|
|
16
|
+
|
|
17
|
+
.tos-content :deep(header) {
|
|
18
|
+
@apply font-bold text-neutral-highlighted;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tos-content :deep(ul) {
|
|
22
|
+
@apply space-y-1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.tos-content :deep(ul li span:first-child) {
|
|
26
|
+
@apply mr-1;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { FormErrorEvent, Form } from '@nuxt/ui'
|
|
4
|
+
|
|
5
|
+
const { t } = useI18n()
|
|
6
|
+
const { openDeclineTosModal } = useConnectAuthModals()
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
hasReachedBottom: boolean
|
|
10
|
+
disableButtons: boolean
|
|
11
|
+
loading: boolean
|
|
12
|
+
}>()
|
|
13
|
+
|
|
14
|
+
const state = reactive({
|
|
15
|
+
agreeToTerms: false
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const formRef = useTemplateRef<Form<unknown>>('form-ref')
|
|
19
|
+
|
|
20
|
+
const schema = z.object({
|
|
21
|
+
agreeToTerms: z.boolean()
|
|
22
|
+
}).superRefine((val, ctx) => {
|
|
23
|
+
if (!val.agreeToTerms) {
|
|
24
|
+
ctx.addIssue({
|
|
25
|
+
code: 'custom',
|
|
26
|
+
message: t('connect.validation.acceptTermsOfUse'),
|
|
27
|
+
path: ['agreeToTerms']
|
|
28
|
+
})
|
|
29
|
+
} else if (!props.hasReachedBottom) {
|
|
30
|
+
ctx.addIssue({
|
|
31
|
+
code: 'custom',
|
|
32
|
+
message: t('connect.validation.termsOfUseScrollToBottom'),
|
|
33
|
+
path: ['agreeToTerms']
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
function onFormSubmitError(event: FormErrorEvent) {
|
|
39
|
+
if (event?.errors?.[0]?.id) {
|
|
40
|
+
const element = document.getElementById(event.errors[0].id)
|
|
41
|
+
if (element) {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
element.focus({ preventScroll: true })
|
|
44
|
+
}, 0)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// reset form errors if user reaches bottom of page
|
|
50
|
+
watch(() => props.hasReachedBottom, (newVal) => {
|
|
51
|
+
if (newVal) {
|
|
52
|
+
formRef.value?.clear()
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<UForm
|
|
59
|
+
ref="form-ref"
|
|
60
|
+
class="sticky bottom-0 flex w-full flex-col items-start justify-between
|
|
61
|
+
gap-4 border-t border-line bg-shade py-4 sm:flex-row sm:items-center sm:gap-0 sm:pb-8"
|
|
62
|
+
:state
|
|
63
|
+
:schema
|
|
64
|
+
@error="onFormSubmitError"
|
|
65
|
+
>
|
|
66
|
+
<UFormField
|
|
67
|
+
v-slot="{ error }"
|
|
68
|
+
name="agreeToTerms"
|
|
69
|
+
:ui="{
|
|
70
|
+
error: 'text-base',
|
|
71
|
+
}"
|
|
72
|
+
>
|
|
73
|
+
<UCheckbox
|
|
74
|
+
ref="checkboxRef"
|
|
75
|
+
v-model="state.agreeToTerms"
|
|
76
|
+
:label="$t('connect.text.iHaveReadAndAcceptTermsOfUse')"
|
|
77
|
+
:ui="{
|
|
78
|
+
label: error ? 'text-lg text-error' : 'text-lg',
|
|
79
|
+
}"
|
|
80
|
+
/>
|
|
81
|
+
</UFormField>
|
|
82
|
+
<div class="flex w-full gap-4 sm:w-fit">
|
|
83
|
+
<UButton
|
|
84
|
+
class="flex-1 sm:flex-none"
|
|
85
|
+
:ui="{ base: 'flex justify-center items-center' }"
|
|
86
|
+
:label="$t('connect.label.accept')"
|
|
87
|
+
:disabled="disableButtons"
|
|
88
|
+
:loading
|
|
89
|
+
type="submit"
|
|
90
|
+
/>
|
|
91
|
+
<UButton
|
|
92
|
+
class="flex-1 sm:flex-none"
|
|
93
|
+
:ui="{ base: 'flex justify-center items-center' }"
|
|
94
|
+
:label="$t('connect.label.decline')"
|
|
95
|
+
variant="outline"
|
|
96
|
+
:disabled="disableButtons"
|
|
97
|
+
@click="openDeclineTosModal"
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
</UForm>
|
|
101
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="bg-yellow-100 p-5">
|
|
3
|
+
Auth - should have bg-yellow-100
|
|
4
|
+
<HelloWorld />
|
|
5
|
+
<h3 class="text-red-700">
|
|
6
|
+
Auth - should be red-700
|
|
7
|
+
</h3>
|
|
8
|
+
<p class="text-brand-inverted text-xl lg:text-3xl">
|
|
9
|
+
Auth - should be brand-inverted
|
|
10
|
+
</p>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export const useAuthApi = () => {
|
|
2
|
+
const { $authApi } = useNuxtApp()
|
|
3
|
+
const queryCache = useQueryCache()
|
|
4
|
+
|
|
5
|
+
async function getAuthUserProfile() {
|
|
6
|
+
const query = defineQuery({
|
|
7
|
+
key: ['auth-user-profile'],
|
|
8
|
+
query: () => $authApi<ConnectAuthProfile>('/users/@me', {
|
|
9
|
+
parseResponse: JSON.parse
|
|
10
|
+
}),
|
|
11
|
+
staleTime: 300000
|
|
12
|
+
})
|
|
13
|
+
return query()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Validates whether an account name is available by sending a request to the AUTH service.
|
|
18
|
+
* @param {string} accountName - The account name to validate for uniqueness.
|
|
19
|
+
*/
|
|
20
|
+
function verifyAccountName(accountName: string) {
|
|
21
|
+
const query = defineQuery({
|
|
22
|
+
key: ['auth-account-name', accountName],
|
|
23
|
+
query: () => $authApi.raw(`/orgs?validateName=true&name=${encodeURIComponent(accountName)}`),
|
|
24
|
+
staleTime: 300000
|
|
25
|
+
})
|
|
26
|
+
return query()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an account by POSTing the given payload to `/orgs`.
|
|
31
|
+
* @returns Object containing mutation state and `createAccount` function.
|
|
32
|
+
*/
|
|
33
|
+
const useCreateAccount = defineMutation(() => {
|
|
34
|
+
const { mutateAsync, ...mutation } = useMutation({
|
|
35
|
+
mutation: (vars: {
|
|
36
|
+
payload: ConnectCreateAccount
|
|
37
|
+
successCb?: (createRes: ConnectAuthProfile) => Promise<unknown>
|
|
38
|
+
}) => {
|
|
39
|
+
return $authApi<ConnectAuthProfile>('/orgs', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
body: vars.payload
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
onError: (error) => {
|
|
45
|
+
// TODO: FUTURE - add api error message to modal content - remove console.error
|
|
46
|
+
console.error('ERROR: ', error)
|
|
47
|
+
useConnectAuthModals().openCreateAccountModal()
|
|
48
|
+
},
|
|
49
|
+
onSuccess: async (_, _vars) => {
|
|
50
|
+
await queryCache.invalidateQueries({ key: ['auth-user-profile'], exact: true })
|
|
51
|
+
if (_vars.successCb) {
|
|
52
|
+
await _vars.successCb(_)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...mutation,
|
|
59
|
+
createAccount: mutateAsync
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Updates a users contact by PUTing the given payload to `/users/contacts`.
|
|
65
|
+
* @returns Object containing mutation state and `updateUserContact` function.
|
|
66
|
+
*/
|
|
67
|
+
const useUpdateOrCreateUserContact = defineMutation(() => {
|
|
68
|
+
const { mutateAsync, ...mutation } = useMutation({
|
|
69
|
+
mutation: (vars: {
|
|
70
|
+
email: string
|
|
71
|
+
phone: string
|
|
72
|
+
phoneExtension: string | undefined
|
|
73
|
+
method?: 'POST' | 'PUT'
|
|
74
|
+
successCb?: () => Promise<unknown>
|
|
75
|
+
errorCb?: (error: unknown) => Promise<unknown>
|
|
76
|
+
}) => {
|
|
77
|
+
return $authApi<ConnectAuthProfile>('/users/contacts', {
|
|
78
|
+
method: vars.method || 'PUT',
|
|
79
|
+
body: {
|
|
80
|
+
email: vars.email,
|
|
81
|
+
phone: vars.phone,
|
|
82
|
+
phoneExtension: vars.phoneExtension
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
onError: async (error, _vars) => {
|
|
87
|
+
// TODO: FUTURE - add api error message to modal content - remove console.error
|
|
88
|
+
console.error('ERROR: ', error)
|
|
89
|
+
await useConnectAuthModals().openUpdateUserContactModal()
|
|
90
|
+
|
|
91
|
+
if (_vars.errorCb) {
|
|
92
|
+
await queryCache.invalidateQueries({ key: ['auth-user-profile'], exact: true })
|
|
93
|
+
await _vars.errorCb(error)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onSuccess: async (_, _vars) => {
|
|
97
|
+
if (_vars.successCb) {
|
|
98
|
+
await _vars.successCb()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...mutation,
|
|
105
|
+
updateOrCreateUserContact: mutateAsync
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
async function getTermsOfUse() {
|
|
110
|
+
const query = defineQuery({
|
|
111
|
+
key: ['auth-terms-of-use'],
|
|
112
|
+
query: () => $authApi<ConnectTermsOfUse>('/documents/termsofuse'),
|
|
113
|
+
staleTime: 300000
|
|
114
|
+
})
|
|
115
|
+
return query()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const usePatchTermsOfUse = defineMutation(() => {
|
|
119
|
+
const { mutateAsync, ...mutation } = useMutation({
|
|
120
|
+
mutation: (vars: { accepted: boolean, version: string, successCb?: () => Promise<unknown> }) => {
|
|
121
|
+
return $authApi<ConnectAuthProfile>('/users/@me', {
|
|
122
|
+
method: 'PATCH',
|
|
123
|
+
body: {
|
|
124
|
+
istermsaccepted: vars.accepted,
|
|
125
|
+
termsversion: vars.version
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
onError: (error) => {
|
|
130
|
+
// TODO: FUTURE - add api error message to modal content - remove console.error
|
|
131
|
+
console.error('ERROR: ', error)
|
|
132
|
+
useConnectAuthModals().openPatchTosErrorModal()
|
|
133
|
+
},
|
|
134
|
+
onSuccess: async (_, _vars) => {
|
|
135
|
+
await queryCache.invalidateQueries({ key: ['auth-user-profile'], exact: true })
|
|
136
|
+
if (_vars.successCb) {
|
|
137
|
+
await _vars.successCb()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
...mutation,
|
|
144
|
+
patchTermsOfUse: mutateAsync
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
getAuthUserProfile,
|
|
150
|
+
getTermsOfUse,
|
|
151
|
+
useCreateAccount,
|
|
152
|
+
usePatchTermsOfUse,
|
|
153
|
+
useUpdateOrCreateUserContact,
|
|
154
|
+
verifyAccountName
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RouteLocationNormalizedGeneric } from '#vue-router'
|
|
2
|
+
|
|
3
|
+
export const useConnectAccountFlowRedirect = () => {
|
|
4
|
+
function finalRedirect(route: RouteLocationNormalizedGeneric, manageAccount = false) {
|
|
5
|
+
const { authUser } = useConnectAuth()
|
|
6
|
+
const { currentAccount, userAccounts } = useConnectAccountStore()
|
|
7
|
+
const localePath = useLocalePath()
|
|
8
|
+
const ac = useAppConfig().connect.login
|
|
9
|
+
const externalRedirectUrl = route.query.return
|
|
10
|
+
? decodeURIComponent(route.query.return as string)
|
|
11
|
+
: undefined
|
|
12
|
+
const internalRedirectUrl = ac.redirect
|
|
13
|
+
const query = { ...route.query }
|
|
14
|
+
query.accountid = String(currentAccount.id)
|
|
15
|
+
|
|
16
|
+
const bypassAccounts = userAccounts.length === 1 && !query.token
|
|
17
|
+
const isNonStaffAccount = ![AccountType.STAFF, AccountType.SBC_STAFF].includes(currentAccount.accountType)
|
|
18
|
+
const createOrSelectAccount = manageAccount && isNonStaffAccount && !bypassAccounts
|
|
19
|
+
|
|
20
|
+
if (createOrSelectAccount) {
|
|
21
|
+
const isBcscUserWithNoAccounts = (!userAccounts.length || userAccounts.length === 0)
|
|
22
|
+
&& authUser.value.loginSource === ConnectLoginSource.BCSC
|
|
23
|
+
const redirectPath = isBcscUserWithNoAccounts ? '/auth/account/create' : '/auth/account/select'
|
|
24
|
+
|
|
25
|
+
return navigateTo({ path: localePath(redirectPath), query })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (externalRedirectUrl) {
|
|
29
|
+
const cleanQuery = { ...query }
|
|
30
|
+
delete cleanQuery.return
|
|
31
|
+
|
|
32
|
+
return navigateTo(
|
|
33
|
+
{
|
|
34
|
+
path: appendUrlParam(
|
|
35
|
+
externalRedirectUrl,
|
|
36
|
+
'accountid',
|
|
37
|
+
currentAccount.id
|
|
38
|
+
),
|
|
39
|
+
query: cleanQuery
|
|
40
|
+
},
|
|
41
|
+
{ external: true }
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return navigateTo({
|
|
46
|
+
path: localePath(internalRedirectUrl),
|
|
47
|
+
query
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
finalRedirect
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useAppConfig } from '#imports'
|
|
2
|
+
|
|
3
|
+
export const useConnectAppConfig = () => {
|
|
4
|
+
/**
|
|
5
|
+
* Merge preset overrides (from app.config.connectOverrides) into the provided baseConfig.
|
|
6
|
+
* If no override for the preset is found, baseConfig is returned unchanged.
|
|
7
|
+
*/
|
|
8
|
+
function mergeAppConfigOverrides(
|
|
9
|
+
baseConfig: ConnectConfig,
|
|
10
|
+
presetName: ConnectPresetType
|
|
11
|
+
): ConnectConfig {
|
|
12
|
+
const appConfig = useAppConfig()
|
|
13
|
+
const overrides = appConfig.connectOverrides?.[presetName] ?? null
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...baseConfig,
|
|
17
|
+
// Apply shallow merge for each subtree when present
|
|
18
|
+
...(overrides?.login
|
|
19
|
+
? { login: { ...baseConfig.login, ...overrides?.login } }
|
|
20
|
+
: { login: baseConfig.login }),
|
|
21
|
+
...(overrides?.header
|
|
22
|
+
? { header: { ...baseConfig.header, ...overrides?.header } }
|
|
23
|
+
: { header: baseConfig.header }),
|
|
24
|
+
logout: baseConfig.logout
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
mergeAppConfigOverrides
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export const useConnectAuth = () => {
|
|
2
|
+
const { $connectAuth } = useNuxtApp()
|
|
3
|
+
const rtc = useRuntimeConfig().public
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Logs the user in using the idpHint 'bcsc', 'idir' or 'bceid' and an optional redirect URL.
|
|
7
|
+
* @param idpHint - The identity provider hint to use for login.
|
|
8
|
+
* @param redirect - An optional URL to redirect to after login. Defaults to location.origin + the current locale
|
|
9
|
+
* @returns A promise that resolves when login is complete.
|
|
10
|
+
*/
|
|
11
|
+
function login(idpHint: ConnectIdpHint, redirect?: string): Promise<void> {
|
|
12
|
+
const redirectUri = redirect ?? window.location.href
|
|
13
|
+
|
|
14
|
+
return $connectAuth.login(
|
|
15
|
+
{
|
|
16
|
+
idpHint,
|
|
17
|
+
redirectUri
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Logs the user out with an optional redirect URL.
|
|
24
|
+
* @param redirect - An optional URL to redirect to after logout. Defaults to location.origin + the current locale
|
|
25
|
+
* @returns A promise that resolves when logout is complete.
|
|
26
|
+
*/
|
|
27
|
+
function logout(redirect?: string): Promise<void> {
|
|
28
|
+
const siteminderUrl = rtc.siteminderLogoutUrl
|
|
29
|
+
let redirectUri = redirect ?? window.location.href
|
|
30
|
+
|
|
31
|
+
if (siteminderUrl) {
|
|
32
|
+
const cleanedUri = redirectUri.replace(/(https?:\/\/)|(\/)+/g, '$1$2')
|
|
33
|
+
redirectUri = `${siteminderUrl}?returl=${encodeURIComponent(cleanedUri)}&retnow=1`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
resetPiniaStores()
|
|
37
|
+
return $connectAuth.logout({
|
|
38
|
+
redirectUri
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isAuthenticated = computed<boolean | undefined>(() => {
|
|
43
|
+
if (!$connectAuth) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
return $connectAuth.authenticated
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const authUser = computed<ConnectAuthUser>(() => {
|
|
50
|
+
if ($connectAuth && $connectAuth.tokenParsed) {
|
|
51
|
+
return {
|
|
52
|
+
firstName: $connectAuth.tokenParsed.firstname,
|
|
53
|
+
lastName: $connectAuth.tokenParsed.lastname,
|
|
54
|
+
fullName: $connectAuth.tokenParsed.name,
|
|
55
|
+
userName: $connectAuth.tokenParsed.username,
|
|
56
|
+
email: $connectAuth.tokenParsed.email,
|
|
57
|
+
keycloakGuid: $connectAuth.tokenParsed.sub || '',
|
|
58
|
+
loginSource: $connectAuth.tokenParsed.loginSource,
|
|
59
|
+
roles: $connectAuth.tokenParsed.realm_access?.roles || []
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {} as ConnectAuthUser
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the current session token, with an optional force refresh.
|
|
67
|
+
* @param forceRefresh - A boolean to force a token refresh.
|
|
68
|
+
* @returns The session token or undefined if the token can't be retrieved.
|
|
69
|
+
*/
|
|
70
|
+
async function getToken(forceRefresh = false): Promise<string | undefined> {
|
|
71
|
+
const minValidity = forceRefresh ? -1 : 30
|
|
72
|
+
return await $connectAuth
|
|
73
|
+
.updateToken(minValidity)
|
|
74
|
+
.then((_refreshed) => {
|
|
75
|
+
return $connectAuth.token
|
|
76
|
+
})
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
console.error(`Failed to get session token: ${error}`)
|
|
79
|
+
return undefined
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
login,
|
|
85
|
+
logout,
|
|
86
|
+
getToken,
|
|
87
|
+
isAuthenticated,
|
|
88
|
+
authUser
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const useConnectAuthModals = () => {
|
|
2
|
+
const { baseModal } = useConnectModal()
|
|
3
|
+
const { logout } = useConnectAuth()
|
|
4
|
+
const t = useNuxtApp().$i18n.t
|
|
5
|
+
|
|
6
|
+
function openDeclineTosModal() {
|
|
7
|
+
baseModal.open({
|
|
8
|
+
title: `${t('connect.label.declineTermsOfUse')}?`,
|
|
9
|
+
description: t('connect.text.declineTOSCantAccessService'),
|
|
10
|
+
dismissible: true,
|
|
11
|
+
buttons: [
|
|
12
|
+
{
|
|
13
|
+
label: t('connect.label.declineTermsOfUse'),
|
|
14
|
+
onClick: async () => await logout()
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: t('connect.label.cancel'),
|
|
18
|
+
shouldClose: true,
|
|
19
|
+
variant: 'outline'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// TODO: better error text
|
|
26
|
+
function openPatchTosErrorModal() {
|
|
27
|
+
baseModal.open({
|
|
28
|
+
title: `${t('connect.text.patchTosError.title')}`,
|
|
29
|
+
description: t('connect.text.patchTosError.description'),
|
|
30
|
+
dismissible: true,
|
|
31
|
+
buttons: [
|
|
32
|
+
{
|
|
33
|
+
label: t('connect.label.close'),
|
|
34
|
+
shouldClose: true
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
// contact info ???
|
|
38
|
+
// include api error message?
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function openCreateAccountModal() {
|
|
43
|
+
baseModal.open({
|
|
44
|
+
title: `${t('connect.text.accountCreationError.title')}`,
|
|
45
|
+
description: t('connect.text.accountCreationError.description'),
|
|
46
|
+
dismissible: true,
|
|
47
|
+
buttons: [
|
|
48
|
+
{
|
|
49
|
+
label: t('connect.label.close'),
|
|
50
|
+
shouldClose: true
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function openUpdateUserContactModal() {
|
|
57
|
+
baseModal.open({
|
|
58
|
+
title: `${t('connect.text.userContactUpdateError.title')}`,
|
|
59
|
+
description: t('connect.text.userContactUpdateError.description'),
|
|
60
|
+
dismissible: true,
|
|
61
|
+
buttons: [
|
|
62
|
+
{
|
|
63
|
+
label: t('connect.label.close'),
|
|
64
|
+
shouldClose: true
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
openCreateAccountModal,
|
|
72
|
+
openDeclineTosModal,
|
|
73
|
+
openPatchTosErrorModal,
|
|
74
|
+
openUpdateUserContactModal
|
|
75
|
+
}
|
|
76
|
+
}
|