@sbc-connect/nuxt-auth 0.4.0 → 0.5.0
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 +16 -0
- package/app/components/Connect/Header/AccountOptionsMenu.vue +1 -1
- package/app/composables/useAuthApi.ts +5 -4
- package/app/composables/useConnectAccountFlowRedirect.ts +25 -10
- package/app/middleware/connect-auth.ts +30 -19
- package/app/pages/auth/login.vue +2 -1
- package/app/pages/auth/terms-of-use.vue +1 -1
- package/app/stores/connect-account.ts +17 -9
- package/nuxt.config.ts +2 -1
- package/package.json +4 -4
- 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
- package/app/middleware/connect-login-page.ts +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @sbc-connect/nuxt-auth
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#123](https://github.com/bcgov/connect-nuxt/pull/123) [`3c33132`](https://github.com/bcgov/connect-nuxt/commit/3c331327a27cfbd0613c268abf97842288d10f8c) Thanks [@cameron-eyds](https://github.com/cameron-eyds)! - Auth Redirect Enhancements
|
|
8
|
+
|
|
9
|
+
## 0.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#121](https://github.com/bcgov/connect-nuxt/pull/121) [`e4d8d9e`](https://github.com/bcgov/connect-nuxt/commit/e4d8d9e510af321a2cc7ba12ca270a5f018981e5) Thanks [@kialj876](https://github.com/kialj876)! - Updated account mocking so that tests can mock their own account instead of the hardcoded mock
|
|
14
|
+
|
|
15
|
+
- Updated dependencies []:
|
|
16
|
+
- @sbc-connect/nuxt-base@0.6.0
|
|
17
|
+
- @sbc-connect/nuxt-forms@0.4.0
|
|
18
|
+
|
|
3
19
|
## 0.4.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ConnectCreateAccount } from '#auth/app/interfaces/connect-account'
|
|
2
|
-
|
|
3
1
|
export const useAuthApi = () => {
|
|
4
2
|
const { $authApi } = useNuxtApp()
|
|
5
3
|
const queryCache = useQueryCache()
|
|
@@ -34,7 +32,10 @@ export const useAuthApi = () => {
|
|
|
34
32
|
*/
|
|
35
33
|
const useCreateAccount = defineMutation(() => {
|
|
36
34
|
const { mutateAsync, ...mutation } = useMutation({
|
|
37
|
-
mutation: (vars: {
|
|
35
|
+
mutation: (vars: {
|
|
36
|
+
payload: ConnectCreateAccount
|
|
37
|
+
successCb?: (createRes: ConnectAuthProfile) => Promise<unknown>
|
|
38
|
+
}) => {
|
|
38
39
|
return $authApi<ConnectAuthProfile>('/orgs', {
|
|
39
40
|
method: 'POST',
|
|
40
41
|
body: vars.payload
|
|
@@ -48,7 +49,7 @@ export const useAuthApi = () => {
|
|
|
48
49
|
onSuccess: async (_, _vars) => {
|
|
49
50
|
await queryCache.invalidateQueries({ key: ['auth-user-profile'], exact: true })
|
|
50
51
|
if (_vars.successCb) {
|
|
51
|
-
await _vars.successCb()
|
|
52
|
+
await _vars.successCb(_)
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RouteLocationNormalizedGeneric } from '#vue-router'
|
|
2
2
|
|
|
3
3
|
export const useConnectAccountFlowRedirect = () => {
|
|
4
|
-
function finalRedirect(route: RouteLocationNormalizedGeneric) {
|
|
4
|
+
function finalRedirect(route: RouteLocationNormalizedGeneric, manageAccount = false) {
|
|
5
|
+
const { authUser } = useConnectAuth()
|
|
6
|
+
const { userAccounts } = useConnectAccountStore()
|
|
5
7
|
const localePath = useLocalePath()
|
|
6
8
|
const ac = useAppConfig().connect.login
|
|
7
9
|
const externalRedirectUrl = route.query.return as string | undefined
|
|
@@ -9,24 +11,37 @@ export const useConnectAccountFlowRedirect = () => {
|
|
|
9
11
|
|
|
10
12
|
const query = { ...route.query }
|
|
11
13
|
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
+
if (manageAccount && userAccounts.length !== 1) {
|
|
15
|
+
const isBcscCreate
|
|
16
|
+
= userAccounts.length === 0
|
|
17
|
+
&& authUser.value.loginSource === ConnectLoginSource.BCSC
|
|
18
|
+
|
|
19
|
+
return isBcscCreate
|
|
20
|
+
? navigateTo({ path: localePath('/auth/account/create'), query })
|
|
21
|
+
: navigateTo({ path: localePath('/auth/account/select'), query })
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
if (externalRedirectUrl) {
|
|
25
|
+
const cleanQuery = { ...query }
|
|
26
|
+
delete cleanQuery.return
|
|
27
|
+
|
|
17
28
|
return navigateTo(
|
|
18
29
|
{
|
|
19
|
-
path: appendUrlParam(
|
|
20
|
-
|
|
30
|
+
path: appendUrlParam(
|
|
31
|
+
externalRedirectUrl,
|
|
32
|
+
'accountid',
|
|
33
|
+
useConnectAccountStore().currentAccount.id
|
|
34
|
+
),
|
|
35
|
+
query: cleanQuery
|
|
21
36
|
},
|
|
22
37
|
{ external: true }
|
|
23
38
|
)
|
|
24
|
-
} else {
|
|
25
|
-
return navigateTo({
|
|
26
|
-
path: localePath(internalRedirectUrl),
|
|
27
|
-
query
|
|
28
|
-
})
|
|
29
39
|
}
|
|
40
|
+
|
|
41
|
+
return navigateTo({
|
|
42
|
+
path: localePath(internalRedirectUrl),
|
|
43
|
+
query
|
|
44
|
+
})
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
return {
|
|
@@ -5,27 +5,33 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
5
5
|
const authApi = useAuthApi()
|
|
6
6
|
const { finalRedirect } = useConnectAccountFlowRedirect()
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const isLoginPage = to.meta.connectLogin === true
|
|
9
|
+
const isTosPage = to.meta.connectTosPage === true
|
|
10
|
+
|
|
11
|
+
if (!isAuthenticated.value && !isLoginPage && !rtc.playwright) {
|
|
12
|
+
const defaultReturn = `${rtc.baseUrl}${to.fullPath.slice(1)}`
|
|
13
|
+
const returnUrl = (to.query.return && String(to.query.return)) || defaultReturn
|
|
14
|
+
|
|
15
|
+
return navigateTo(
|
|
16
|
+
{
|
|
17
|
+
path: localePath('/auth/login'),
|
|
18
|
+
query: {
|
|
19
|
+
...to.query,
|
|
20
|
+
return: returnUrl
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
|
-
|
|
23
|
+
)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
if (isAuthenticated.value) {
|
|
20
27
|
const { data, refresh } = await authApi.getAuthUserProfile()
|
|
21
28
|
await refresh()
|
|
22
29
|
const hasAccepted = data.value?.userTerms.isTermsOfUseAccepted
|
|
23
|
-
const isTosPage = to.meta.connectTosPage === true
|
|
24
30
|
if (!hasAccepted && !isTosPage) {
|
|
25
31
|
const query = { ...to.query }
|
|
26
32
|
return navigateTo({ path: localePath('/auth/terms-of-use'), query })
|
|
27
|
-
} else if (hasAccepted && isTosPage) {
|
|
28
|
-
return finalRedirect(to)
|
|
33
|
+
} else if (hasAccepted && (isTosPage || isLoginPage)) {
|
|
34
|
+
return finalRedirect(to, true)
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
@@ -45,14 +51,19 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
45
51
|
}
|
|
46
52
|
$connectAuth.authenticated = true
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (rtc.playwrightFetchTestAccount) {
|
|
55
|
+
// allows each test to mock the account information with its own data
|
|
56
|
+
await useConnectAccountStore().setAccountInfo()
|
|
57
|
+
} else {
|
|
58
|
+
currentAccount.value = {
|
|
59
|
+
id: 1,
|
|
60
|
+
label: 'Playwright',
|
|
61
|
+
accountStatus: AccountStatus.ACTIVE,
|
|
62
|
+
accountType: AccountType.PREMIUM,
|
|
63
|
+
type: UserSettingsType.ACCOUNT,
|
|
64
|
+
urlorigin: '',
|
|
65
|
+
urlpath: ''
|
|
66
|
+
}
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
69
|
})
|
package/app/pages/auth/login.vue
CHANGED
|
@@ -12,7 +12,8 @@ useHead({
|
|
|
12
12
|
definePageMeta({
|
|
13
13
|
layout: 'connect-auth',
|
|
14
14
|
hideBreadcrumbs: true,
|
|
15
|
-
middleware: 'connect-
|
|
15
|
+
middleware: 'connect-auth',
|
|
16
|
+
connectLogin: true
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
const isSessionExpired = sessionStorage.getItem(ConnectAuthStorageKey.CONNECT_SESSION_EXPIRED)
|
|
@@ -70,7 +70,7 @@ const disableButtons = computed<boolean>(() => {
|
|
|
70
70
|
@submit="patchTermsOfUse({
|
|
71
71
|
accepted: true,
|
|
72
72
|
version: data!.versionId,
|
|
73
|
-
successCb: async () => await finalRedirect(useRoute()),
|
|
73
|
+
successCb: async () => await finalRedirect(useRoute(), true),
|
|
74
74
|
})"
|
|
75
75
|
/>
|
|
76
76
|
</UContainer>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getAccountCreateSchema } from '#auth/app/utils/schemas/account'
|
|
2
2
|
import type { AccountProfileSchema } from '#auth/app/utils/schemas/account'
|
|
3
|
-
import type { ConnectCreateAccount } from '#auth/app/interfaces/connect-account'
|
|
4
3
|
|
|
5
4
|
export const useConnectAccountStore = defineStore('connect-auth-account-store', () => {
|
|
6
5
|
const { $authApi } = useNuxtApp()
|
|
@@ -88,13 +87,22 @@ export const useConnectAccountStore = defineStore('connect-auth-account-store',
|
|
|
88
87
|
await createAccount({
|
|
89
88
|
payload,
|
|
90
89
|
// Update User Contact Info on create account success
|
|
91
|
-
successCb: async () =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
successCb: async (createResponse: ConnectAuthProfile) => {
|
|
91
|
+
// Refresh and switch to new account prior to redirect
|
|
92
|
+
if (createResponse?.id) {
|
|
93
|
+
await setAccountInfo()
|
|
94
|
+
switchCurrentAccount(createResponse.id)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Update user contact and then redirect regardless of success or failure
|
|
98
|
+
await updateUserContact({
|
|
99
|
+
email: accountFormState.emailAddress,
|
|
100
|
+
phone: accountFormState.phone.phoneNumber,
|
|
101
|
+
phoneExtension: accountFormState.phone.ext,
|
|
102
|
+
successCb: async () => await finalRedirect(useRoute()),
|
|
103
|
+
errorCb: async () => await finalRedirect(useRoute())
|
|
104
|
+
})
|
|
105
|
+
}
|
|
98
106
|
})
|
|
99
107
|
} catch (error) {
|
|
100
108
|
// Error handled in useAuthApi
|
|
@@ -119,7 +127,7 @@ export const useConnectAccountStore = defineStore('connect-auth-account-store',
|
|
|
119
127
|
|
|
120
128
|
/** Get the user's account list */
|
|
121
129
|
async function getUserAccounts(): Promise<ConnectAccount[] | undefined> {
|
|
122
|
-
if (!authUser.value?.keycloakGuid) {
|
|
130
|
+
if (!authUser.value?.keycloakGuid && !rtc.playwright) {
|
|
123
131
|
return undefined
|
|
124
132
|
}
|
|
125
133
|
// TODO: use orgs fetch instead to get branch name ? $authApi<UserSettings[]>('/users/orgs')
|
package/nuxt.config.ts
CHANGED
|
@@ -77,7 +77,8 @@ export default defineNuxtConfig({
|
|
|
77
77
|
tokenMinValidity: '',
|
|
78
78
|
sessionInactivityTimeout: '',
|
|
79
79
|
sessionModalTimeout: '',
|
|
80
|
-
playwright: process.env.playwright === 'true'
|
|
80
|
+
playwright: process.env.playwright === 'true',
|
|
81
|
+
playwrightFetchTestAccount: process.env.playwrightFetchTestAccount === 'true'
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sbc-connect/nuxt-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"repository": "github:bcgov/connect-nuxt",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"nuxt": "4.2.2",
|
|
12
12
|
"typescript": "5.9.3",
|
|
13
13
|
"vue-tsc": "3.2.1",
|
|
14
|
-
"@sbc-connect/
|
|
15
|
-
"@sbc-connect/
|
|
16
|
-
"@sbc-connect/
|
|
14
|
+
"@sbc-connect/eslint-config": "0.0.8",
|
|
15
|
+
"@sbc-connect/playwright-config": "0.1.1",
|
|
16
|
+
"@sbc-connect/vitest-config": "0.1.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@pinia/colada": "0.20.0",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { createResolver } from 'nuxt/kit'
|
|
3
|
+
|
|
4
|
+
const { resolve } = createResolver(import.meta.url)
|
|
5
|
+
|
|
6
|
+
export const getUserProfileMock = () => {
|
|
7
|
+
const json: ConnectAuthProfile = JSON.parse(fs.readFileSync(resolve('./json/PUBLIC_USER.json'), 'utf8'))
|
|
8
|
+
return json
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contacts": [
|
|
3
|
+
{
|
|
4
|
+
"email": "v9x3z!q__mock@fuzzmail.zzz",
|
|
5
|
+
"phone": "(902) 555-xyzz",
|
|
6
|
+
"phoneExtension": "7q1"
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"created": "2024-03-19T04:92:17+00:00",
|
|
10
|
+
"firstname": "Nxlqrp3##",
|
|
11
|
+
"id": 88422,
|
|
12
|
+
"idpUserid": "ZZ91XQWPMR7T4!$CBA9900PLMNXXQTT",
|
|
13
|
+
"keycloakGuid": "xxxxxxxx-bb77-49c1-f01a-xxxxxxxxx",
|
|
14
|
+
"lastname": "T'W&&two--",
|
|
15
|
+
"loginSource": "BCSC",
|
|
16
|
+
"loginTime": "2026-01-23T28:77:59+00:00",
|
|
17
|
+
"modified": "2026-01-23T28:77:59+00:00",
|
|
18
|
+
"modifiedBy": "Nxlqrp3## T'W&&two--",
|
|
19
|
+
"type": "PUBLIC_USER",
|
|
20
|
+
"userStatus": 1,
|
|
21
|
+
"userTerms": {
|
|
22
|
+
"isTermsOfUseAccepted": true,
|
|
23
|
+
"termsOfUseAcceptedVersion": "999x"
|
|
24
|
+
},
|
|
25
|
+
"username": "bcsc/zz91xqwpmr7t4!$cba9900plmnxxqtt",
|
|
26
|
+
"verified": true,
|
|
27
|
+
"version": 9999
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { createResolver } from 'nuxt/kit'
|
|
3
|
+
|
|
4
|
+
import type { ConnectAccount } from '#auth/app/interfaces/connect-account'
|
|
5
|
+
|
|
6
|
+
const { resolve } = createResolver(import.meta.url)
|
|
7
|
+
|
|
8
|
+
export const getUserSettingsMock = (accountType: AccountType) => {
|
|
9
|
+
const json: ConnectAccount[] = JSON.parse(fs.readFileSync(resolve(`./json/${accountType}.json`), 'utf8'))
|
|
10
|
+
return json
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"accountStatus": "ACTIVE",
|
|
4
|
+
"accountType": "PREMIUM",
|
|
5
|
+
"additionalLabel": "Test Branch 1",
|
|
6
|
+
"id": 1222,
|
|
7
|
+
"label": "Test Tester",
|
|
8
|
+
"productSettings": "/account/1222/restricted-product",
|
|
9
|
+
"type": "ACCOUNT",
|
|
10
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
11
|
+
"urlpath": "/account/1222/settings"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"accountStatus": "ACTIVE",
|
|
15
|
+
"accountType": "PREMIUM",
|
|
16
|
+
"additionalLabel": "Test Branch 2",
|
|
17
|
+
"id": 1223,
|
|
18
|
+
"label": "Test Tester 2",
|
|
19
|
+
"productSettings": "/account/1223/restricted-product",
|
|
20
|
+
"type": "ACCOUNT",
|
|
21
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
22
|
+
"urlpath": "/account/1223/settings"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"id": 1111,
|
|
26
|
+
"label": "USER PROFILE",
|
|
27
|
+
"type": "USER_PROFILE",
|
|
28
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
29
|
+
"urlpath": "/userprofile"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": 1111,
|
|
33
|
+
"label": "CREATE ACCOUNT",
|
|
34
|
+
"type": "CREATE_ACCOUNT",
|
|
35
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
36
|
+
"urlpath": "/setup-account"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"accountStatus": "ACTIVE",
|
|
4
|
+
"accountType": "SBC_STAFF",
|
|
5
|
+
"additionalLabel": "Sbc staff example",
|
|
6
|
+
"id": 1239,
|
|
7
|
+
"label": "Ministry of Finance",
|
|
8
|
+
"productSettings": "/account/1239/restricted-product",
|
|
9
|
+
"type": "ACCOUNT",
|
|
10
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
11
|
+
"urlpath": "/account/1239/settings"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": 1111,
|
|
15
|
+
"label": "USER PROFILE",
|
|
16
|
+
"type": "USER_PROFILE",
|
|
17
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
18
|
+
"urlpath": "/userprofile"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": 1111,
|
|
22
|
+
"label": "CREATE ACCOUNT",
|
|
23
|
+
"type": "CREATE_ACCOUNT",
|
|
24
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
25
|
+
"urlpath": "/setup-account"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"accountStatus": "ACTIVE",
|
|
4
|
+
"accountType": "STAFF",
|
|
5
|
+
"additionalLabel": "BC Registries and Online Services Staff",
|
|
6
|
+
"id": 1234,
|
|
7
|
+
"label": "Ministry of Citizens' Services",
|
|
8
|
+
"productSettings": "/account/1234/restricted-product",
|
|
9
|
+
"type": "ACCOUNT",
|
|
10
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
11
|
+
"urlpath": "/account/1234/settings"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": 1111,
|
|
15
|
+
"label": "USER PROFILE",
|
|
16
|
+
"type": "USER_PROFILE",
|
|
17
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
18
|
+
"urlpath": "/userprofile"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": 1111,
|
|
22
|
+
"label": "CREATE ACCOUNT",
|
|
23
|
+
"type": "CREATE_ACCOUNT",
|
|
24
|
+
"urlorigin": "https://dev.account.bcregistry.gov.bc.ca",
|
|
25
|
+
"urlpath": "/setup-account"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test'
|
|
2
|
+
import { AccountType } from '#auth/app/enums/account-type'
|
|
3
|
+
import { getUserProfileMock, getUserSettingsMock } from '#auth/testMocks/auth'
|
|
4
|
+
|
|
5
|
+
export const mockApiCallsForSetAccount = async (
|
|
6
|
+
page: Page,
|
|
7
|
+
accountType: AccountType = AccountType.PREMIUM
|
|
8
|
+
) => {
|
|
9
|
+
page.route('**/users/@me', async (route) => {
|
|
10
|
+
await route.fulfill({ json: getUserProfileMock() })
|
|
11
|
+
})
|
|
12
|
+
page.route('**/users/**/settings', async (route) => {
|
|
13
|
+
await route.fulfill({ json: getUserSettingsMock(accountType) })
|
|
14
|
+
})
|
|
15
|
+
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export default defineNuxtRouteMiddleware((to) => {
|
|
2
|
-
const { isAuthenticated, authUser } = useConnectAuth()
|
|
3
|
-
const accountStore = useConnectAccountStore()
|
|
4
|
-
const localePath = useLocalePath()
|
|
5
|
-
const { finalRedirect } = useConnectAccountFlowRedirect()
|
|
6
|
-
|
|
7
|
-
const numAccounts = accountStore.userAccounts.length
|
|
8
|
-
|
|
9
|
-
if (isAuthenticated.value) {
|
|
10
|
-
if (numAccounts === 1) {
|
|
11
|
-
return finalRedirect(to)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (numAccounts === 0 && authUser.value.loginSource === ConnectLoginSource.BCSC) {
|
|
15
|
-
return navigateTo({
|
|
16
|
-
path: localePath('/auth/account/create'),
|
|
17
|
-
query: to.query
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return navigateTo({
|
|
22
|
-
path: localePath('/auth/account/select'),
|
|
23
|
-
query: to.query
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
})
|