@sbc-connect/nuxt-auth 0.5.0 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @sbc-connect/nuxt-auth
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`93c5650`](https://github.com/bcgov/connect-nuxt/commit/93c5650be9a6b48e51d876d522f168d885d006c4)]:
8
+ - @sbc-connect/nuxt-forms@0.5.0
9
+
10
+ ## 0.6.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#127](https://github.com/bcgov/connect-nuxt/pull/127) [`63409ea`](https://github.com/bcgov/connect-nuxt/commit/63409eab3ef9072fe8e05662b44f61bb8be6cff4) Thanks [@cameron-eyds](https://github.com/cameron-eyds)! - Improved name lookup validations
15
+
16
+ - [#125](https://github.com/bcgov/connect-nuxt/pull/125) [`fda1d48`](https://github.com/bcgov/connect-nuxt/commit/fda1d48ed55838aeece70aa04a82440153a3db24) Thanks [@cameron-eyds](https://github.com/cameron-eyds)! - Includes contact POST and minor redirect refactors
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`8cc8cc0`](https://github.com/bcgov/connect-nuxt/commit/8cc8cc09aad741dc841a864998129c6ac5a6af2f)]:
21
+ - @sbc-connect/nuxt-base@0.6.1
22
+ - @sbc-connect/nuxt-forms@0.4.1
23
+
3
24
  ## 0.5.0
4
25
 
5
26
  ### Minor Changes
@@ -24,9 +24,16 @@ const formErrors = computed<{
24
24
  }
25
25
  })
26
26
 
27
- async function validate() {
28
- return formRef.value?.validate({ silent: true })
27
+ async function validate(fieldName?: keyof AccountProfileSchema) {
28
+ return formRef.value?.validate({ name: fieldName, silent: true })
29
29
  }
30
+
31
+ watch(() => statusCode.value, async () => {
32
+ if (statusCode.value !== undefined) {
33
+ await nextTick()
34
+ await validate('accountName')
35
+ }
36
+ })
30
37
  </script>
31
38
 
32
39
  <template>
@@ -64,17 +64,18 @@ export const useAuthApi = () => {
64
64
  * Updates a users contact by PUTing the given payload to `/users/contacts`.
65
65
  * @returns Object containing mutation state and `updateUserContact` function.
66
66
  */
67
- const useUpdateUserContact = defineMutation(() => {
67
+ const useUpdateOrCreateUserContact = defineMutation(() => {
68
68
  const { mutateAsync, ...mutation } = useMutation({
69
69
  mutation: (vars: {
70
70
  email: string
71
71
  phone: string
72
72
  phoneExtension: string | undefined
73
+ method?: 'POST' | 'PUT'
73
74
  successCb?: () => Promise<unknown>
74
75
  errorCb?: (error: unknown) => Promise<unknown>
75
76
  }) => {
76
77
  return $authApi<ConnectAuthProfile>('/users/contacts', {
77
- method: 'PUT',
78
+ method: vars.method || 'PUT',
78
79
  body: {
79
80
  email: vars.email,
80
81
  phone: vars.phone,
@@ -101,7 +102,7 @@ export const useAuthApi = () => {
101
102
 
102
103
  return {
103
104
  ...mutation,
104
- updateUserContact: mutateAsync
105
+ updateOrCreateUserContact: mutateAsync
105
106
  }
106
107
  })
107
108
 
@@ -149,7 +150,7 @@ export const useAuthApi = () => {
149
150
  getTermsOfUse,
150
151
  useCreateAccount,
151
152
  usePatchTermsOfUse,
152
- useUpdateUserContact,
153
+ useUpdateOrCreateUserContact,
153
154
  verifyAccountName
154
155
  }
155
156
  }
@@ -3,22 +3,23 @@ import type { RouteLocationNormalizedGeneric } from '#vue-router'
3
3
  export const useConnectAccountFlowRedirect = () => {
4
4
  function finalRedirect(route: RouteLocationNormalizedGeneric, manageAccount = false) {
5
5
  const { authUser } = useConnectAuth()
6
- const { userAccounts } = useConnectAccountStore()
6
+ const { currentAccount, userAccounts } = useConnectAccountStore()
7
7
  const localePath = useLocalePath()
8
8
  const ac = useAppConfig().connect.login
9
9
  const externalRedirectUrl = route.query.return as string | undefined
10
10
  const internalRedirectUrl = ac.redirect
11
-
12
11
  const query = { ...route.query }
13
12
 
14
- if (manageAccount && userAccounts.length !== 1) {
15
- const isBcscCreate
16
- = userAccounts.length === 0
17
- && authUser.value.loginSource === ConnectLoginSource.BCSC
13
+ const bypassAccounts = userAccounts.length === 1 && !query.populate
14
+ const isNonStaffAccount = ![AccountType.STAFF, AccountType.SBC_STAFF].includes(currentAccount.accountType)
15
+ const createOrSelectAccount = manageAccount && isNonStaffAccount && !bypassAccounts
16
+
17
+ if (createOrSelectAccount) {
18
+ const isBcscUserWithNoAccounts = (!userAccounts.length || userAccounts.length === 0)
19
+ && authUser.value.loginSource === ConnectLoginSource.BCSC
20
+ const redirectPath = isBcscUserWithNoAccounts ? '/auth/account/create' : '/auth/account/select'
18
21
 
19
- return isBcscCreate
20
- ? navigateTo({ path: localePath('/auth/account/create'), query })
21
- : navigateTo({ path: localePath('/auth/account/select'), query })
22
+ return navigateTo({ path: localePath(redirectPath), query })
22
23
  }
23
24
 
24
25
  if (externalRedirectUrl) {
@@ -30,7 +31,7 @@ export const useConnectAccountFlowRedirect = () => {
30
31
  path: appendUrlParam(
31
32
  externalRedirectUrl,
32
33
  'accountid',
33
- useConnectAccountStore().currentAccount.id
34
+ currentAccount.id
34
35
  ),
35
36
  query: cleanQuery
36
37
  },
@@ -33,7 +33,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
33
33
  if (idpEnforcement && authUser.value?.loginSource) {
34
34
  // User's IDP is not allowed, log them out and redirect to login page
35
35
  if (!allowedIdps?.includes(authUser.value?.loginSource.toLowerCase() as unknown as ConnectIdpHint)) {
36
- showInvalidIdpModal()
36
+ await showInvalidIdpModal()
37
37
  }
38
38
  }
39
39
  })
@@ -5,7 +5,7 @@ export const useConnectAccountStore = defineStore('connect-auth-account-store',
5
5
  const { $authApi } = useNuxtApp()
6
6
  const rtc = useRuntimeConfig().public
7
7
  const { authUser } = useConnectAuth()
8
- const { useCreateAccount, useUpdateUserContact, getAuthUserProfile } = useAuthApi()
8
+ const { useCreateAccount, useUpdateOrCreateUserContact, getAuthUserProfile } = useAuthApi()
9
9
  const { finalRedirect } = useConnectAccountFlowRedirect()
10
10
 
11
11
  // selected user account
@@ -21,7 +21,7 @@ export const useConnectAccountStore = defineStore('connect-auth-account-store',
21
21
  // Create account
22
22
  const isLoading = ref<boolean>(false)
23
23
  const { createAccount } = useCreateAccount()
24
- const { updateUserContact } = useUpdateUserContact()
24
+ const { updateOrCreateUserContact } = useUpdateOrCreateUserContact()
25
25
  const createAccountProfileSchema = getAccountCreateSchema()
26
26
  const accountFormState = reactive<AccountProfileSchema>(createAccountProfileSchema.parse({}))
27
27
  /**
@@ -94,11 +94,12 @@ export const useConnectAccountStore = defineStore('connect-auth-account-store',
94
94
  switchCurrentAccount(createResponse.id)
95
95
  }
96
96
 
97
- // Update user contact and then redirect regardless of success or failure
98
- await updateUserContact({
97
+ // Update or create user contact and then redirect regardless of success or failure
98
+ await updateOrCreateUserContact({
99
99
  email: accountFormState.emailAddress,
100
100
  phone: accountFormState.phone.phoneNumber,
101
101
  phoneExtension: accountFormState.phone.ext,
102
+ method: userAccounts.value.length === 1 ? 'POST' : 'PUT', // if only 1 account exists then contact is new
102
103
  successCb: async () => await finalRedirect(useRoute()),
103
104
  errorCb: async () => await finalRedirect(useRoute())
104
105
  })
@@ -6,7 +6,7 @@ export function getAccountNameSchema(status?: number | undefined) {
6
6
 
7
7
  return z.string().min(1, t('connect.validation.requiredAccountName'))
8
8
  .superRefine((val, ctx) => {
9
- // Only run if we have a value and a statusCode
9
+ // Validate account name uniqueness based on API response status code
10
10
  if (val && status !== undefined) {
11
11
  if (status === 200) {
12
12
  ctx.addIssue({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sbc-connect/nuxt-auth",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.1",
5
5
  "repository": "github:bcgov/connect-nuxt",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./nuxt.config.ts",
@@ -22,8 +22,8 @@
22
22
  "keycloak-js": "26.2.2",
23
23
  "pinia": "3.0.4",
24
24
  "pinia-plugin-persistedstate": "4.7.1",
25
- "@sbc-connect/nuxt-base": "0.6.0",
26
- "@sbc-connect/nuxt-forms": "0.4.0"
25
+ "@sbc-connect/nuxt-base": "0.6.1",
26
+ "@sbc-connect/nuxt-forms": "0.5.0"
27
27
  },
28
28
  "scripts": {
29
29
  "preinstall": "npx only-allow pnpm",