From b45b804c41f7355ea2e848325d965c928cec7c86 Mon Sep 17 00:00:00 2001 From: Jake Loew Date: Wed, 8 May 2024 12:38:08 -0600 Subject: [PATCH] Add 'onAutoRefreshFailure' to vue config --- package.json | 2 + packages/sdk-vue/CHANGES.md | 5 ++ packages/sdk-vue/docs/README.md | 9 ++++ .../docs/interfaces/types.FusionAuth.md | 26 ++++----- .../docs/interfaces/types.FusionAuthConfig.md | 53 ++++++++++++++----- .../sdk-vue/docs/interfaces/types.UserInfo.md | 22 ++++---- .../docs/modules/composables_useFusionAuth.md | 2 +- packages/sdk-vue/package.json | 2 +- .../createFusionAuth/createFusionAuth.test.ts | 29 +++++++++- packages/sdk-vue/src/types.ts | 7 ++- packages/sdk-vue/web-types.json | 4 +- 11 files changed, 117 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 80231d9..866ab6c 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,8 @@ "build:sdk-vue": "yarn build:lexicon && yarn build:core && yarn workspace @fusionauth/vue-sdk build", "yalc-pub:sdk-react": "yarn build:sdk-react && yalc publish packages/sdk-react", "yalc-push:sdk-react": "yarn build:sdk-react && yalc push packages/sdk-react", + "yalc-pub:sdk-vue": "yarn build:sdk-vue && yalc publish packages/sdk-vue", + "yalc-push:sdk-vue": "yarn build:sdk-vue && yalc push packages/sdk-vue", "test": "yarn test:lexicon && yarn test:core && yarn test:sdk-react && yarn test:sdk-angular && yarn test:sdk-vue", "test:core": "yarn workspace @fusionauth-sdk/core test", "test:lexicon": "yarn workspace @fusionauth-sdk/lexicon test", diff --git a/packages/sdk-vue/CHANGES.md b/packages/sdk-vue/CHANGES.md index 453706e..2c985e3 100644 --- a/packages/sdk-vue/CHANGES.md +++ b/packages/sdk-vue/CHANGES.md @@ -1,5 +1,10 @@ fusionauth-vue-sdk Changes +Changes in 1.0.1 + +- Adds `onAutoRefreshFailure` option to `FusionAuthConfig`. +- _Bug fix_ `isLoggedIn` property is set to `false` after token refresh. [See issue #82](https://github.com/FusionAuth/fusionauth-javascript-sdk/issues/82) + Changes in 1.0.0 - _Breaking change_ `isLoggedIn` property -- previously a function -- is now using [Vue's Reactivity API](https://vuejs.org/api/reactivity-core.html). The benefit of this is that it can be used as a reactive property in Vue. diff --git a/packages/sdk-vue/docs/README.md b/packages/sdk-vue/docs/README.md index c9bb94e..e90e90e 100644 --- a/packages/sdk-vue/docs/README.md +++ b/packages/sdk-vue/docs/README.md @@ -16,6 +16,7 @@ An SDK for using FusionAuth in Vue applications. - [Pre-built buttons](#pre-built-buttons) - [Quickstart](#quickstart) - [Documentation](#documentation) + - [Known Issues](#known-issues) - [Releases](#releases) - [Upgrade Policy](#upgrade-policy) @@ -215,6 +216,14 @@ end::forDocSite[] Use backticks for code in this readme. This readme is included on the FusionAuth website, and backticks show the code in the best light there. +## Known issues + +### Nuxt + +This issue affects versions `<=1.0.0`. + +If you are using [Nuxt](https://nuxt.com/) or any type of SSR (server side rendering), the SDK will not work. [See details here.](https://github.com/FusionAuth/fusionauth-javascript-sdk/issues/74) + ## Releases This package is released via GitHub actions. diff --git a/packages/sdk-vue/docs/interfaces/types.FusionAuth.md b/packages/sdk-vue/docs/interfaces/types.FusionAuth.md index c3df852..d44916e 100644 --- a/packages/sdk-vue/docs/interfaces/types.FusionAuth.md +++ b/packages/sdk-vue/docs/interfaces/types.FusionAuth.md @@ -31,7 +31,7 @@ Error occurred within getUserInfo. #### Defined in -[types.ts:113](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L113) +[types.ts:118](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L118) --- @@ -52,7 +52,7 @@ Internally updates `isFetchingUser` and `userInfo` refs, as well as `error` if t #### Defined in -[types.ts:98](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L98) +[types.ts:103](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L103) --- @@ -73,7 +73,7 @@ Refresh is scheduled to happen at the configured `autoRefreshSecondsBeforeExpiry #### Defined in -[types.ts:142](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L142) +[types.ts:147](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L147) --- @@ -85,7 +85,7 @@ Indicates that the getUserInfo call is unresolved. #### Defined in -[types.ts:108](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L108) +[types.ts:113](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L113) --- @@ -97,7 +97,7 @@ Whether the user is logged in. #### Defined in -[types.ts:91](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L91) +[types.ts:96](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L96) --- @@ -123,7 +123,7 @@ Initiates login flow. #### Defined in -[types.ts:119](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L119) +[types.ts:124](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L124) --- @@ -143,28 +143,28 @@ Initiates a logout. #### Defined in -[types.ts:130](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L130) +[types.ts:135](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L135) --- ### refreshToken -• **refreshToken**: () => `Promise`\<`void`\> +• **refreshToken**: () => `Promise`\<`Response`\> Refreshes the access token a single time. Token refreshing is handled automatically if configured with `shouldAutoRefresh`. #### Type declaration -▸ (): `Promise`\<`void`\> +▸ (): `Promise`\<`Response`\> ##### Returns -`Promise`\<`void`\> +`Promise`\<`Response`\> #### Defined in -[types.ts:136](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L136) +[types.ts:141](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L141) --- @@ -190,7 +190,7 @@ Initiates register flow. #### Defined in -[types.ts:125](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L125) +[types.ts:130](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L130) --- @@ -202,4 +202,4 @@ Data fetched from the configured 'me' endpoint. #### Defined in -[types.ts:103](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L103) +[types.ts:108](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L108) diff --git a/packages/sdk-vue/docs/interfaces/types.FusionAuthConfig.md b/packages/sdk-vue/docs/interfaces/types.FusionAuthConfig.md index 2fd787a..37a99d6 100644 --- a/packages/sdk-vue/docs/interfaces/types.FusionAuthConfig.md +++ b/packages/sdk-vue/docs/interfaces/types.FusionAuthConfig.md @@ -15,6 +15,7 @@ Config for the FusionAuth Vue SDK - [loginPath](types.FusionAuthConfig.md#loginpath) - [logoutPath](types.FusionAuthConfig.md#logoutpath) - [mePath](types.FusionAuthConfig.md#mepath) +- [onAutoRefreshFailure](types.FusionAuthConfig.md#onautorefreshfailure) - [onRedirect](types.FusionAuthConfig.md#onredirect) - [redirectUri](types.FusionAuthConfig.md#redirecturi) - [registerPath](types.FusionAuthConfig.md#registerpath) @@ -34,7 +35,7 @@ The number of seconds before the access token expiry when the auto refresh funct #### Defined in -[types.ts:38](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L38) +[types.ts:38](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L38) --- @@ -46,7 +47,7 @@ The client id of the application. #### Defined in -[types.ts:14](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L14) +[types.ts:14](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L14) --- @@ -58,7 +59,7 @@ The path to the login endpoint. #### Defined in -[types.ts:48](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L48) +[types.ts:53](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L53) --- @@ -70,7 +71,7 @@ The path to the logout endpoint. #### Defined in -[types.ts:52](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L52) +[types.ts:57](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L57) --- @@ -82,7 +83,33 @@ The path to the me endpoint. #### Defined in -[types.ts:64](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L64) +[types.ts:69](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L69) + +--- + +### onAutoRefreshFailure + +• `Optional` **onAutoRefreshFailure**: (`error`: `Error`) => `void` + +Callback to be invoked if a request to refresh the access token fails during autorefresh. + +#### Type declaration + +▸ (`error`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `error` | `Error` | + +##### Returns + +`void` + +#### Defined in + +[types.ts:48](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L48) --- @@ -108,7 +135,7 @@ Callback function to be invoked with the `state` value upon redirect from login #### Defined in -[types.ts:43](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L43) +[types.ts:43](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L43) --- @@ -120,7 +147,7 @@ The redirect URI of the application. #### Defined in -[types.ts:18](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L18) +[types.ts:18](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L18) --- @@ -132,7 +159,7 @@ The path to the register endpoint. #### Defined in -[types.ts:56](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L56) +[types.ts:61](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L61) --- @@ -144,7 +171,7 @@ The OAuth2 scope parameter passed to the `/oauth2/authorize` endpoint. If not sp #### Defined in -[types.ts:23](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L23) +[types.ts:23](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L23) --- @@ -156,7 +183,7 @@ The URL of the FusionAuth server. #### Defined in -[types.ts:10](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L10) +[types.ts:10](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L10) --- @@ -168,7 +195,7 @@ Enables the SDK to automatically handle fetching user info when logged in. Defau #### Defined in -[types.ts:33](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L33) +[types.ts:33](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L33) --- @@ -180,7 +207,7 @@ Enables automatic token refreshing. Defaults to false. #### Defined in -[types.ts:28](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L28) +[types.ts:28](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L28) --- @@ -192,4 +219,4 @@ The path to the token refresh endpoint. #### Defined in -[types.ts:60](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L60) +[types.ts:65](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L65) diff --git a/packages/sdk-vue/docs/interfaces/types.UserInfo.md b/packages/sdk-vue/docs/interfaces/types.UserInfo.md index 00b7c27..6a6fdb0 100644 --- a/packages/sdk-vue/docs/interfaces/types.UserInfo.md +++ b/packages/sdk-vue/docs/interfaces/types.UserInfo.md @@ -30,7 +30,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:71](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L71) +[types.ts:76](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L76) --- @@ -40,7 +40,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:72](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L72) +[types.ts:77](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L77) --- @@ -50,7 +50,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:73](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L73) +[types.ts:78](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L78) --- @@ -60,7 +60,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:74](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L74) +[types.ts:79](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L79) --- @@ -70,7 +70,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:75](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L75) +[types.ts:80](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L80) --- @@ -80,7 +80,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:81](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L81) +[types.ts:86](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L86) --- @@ -90,7 +90,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:76](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L76) +[types.ts:81](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L81) --- @@ -100,7 +100,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:77](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L77) +[types.ts:82](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L82) --- @@ -110,7 +110,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:78](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L78) +[types.ts:83](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L83) --- @@ -120,7 +120,7 @@ User information returned from FusionAuth. #### Defined in -[types.ts:79](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L79) +[types.ts:84](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L84) --- @@ -130,4 +130,4 @@ User information returned from FusionAuth. #### Defined in -[types.ts:80](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/types.ts#L80) +[types.ts:85](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/types.ts#L85) diff --git a/packages/sdk-vue/docs/modules/composables_useFusionAuth.md b/packages/sdk-vue/docs/modules/composables_useFusionAuth.md index d2f5e2f..59b0da2 100644 --- a/packages/sdk-vue/docs/modules/composables_useFusionAuth.md +++ b/packages/sdk-vue/docs/modules/composables_useFusionAuth.md @@ -20,4 +20,4 @@ #### Defined in -[composables/useFusionAuth.ts:5](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/fcd17d440e603901f23776175e07b35fc625e758/packages/sdk-vue/src/composables/useFusionAuth.ts#L5) +[composables/useFusionAuth.ts:5](https://github.com/FusionAuth/fusionauth-javascript-sdk/blob/525bfc3280cf0ce66d562e4b96351ecc387e5857/packages/sdk-vue/src/composables/useFusionAuth.ts#L5) diff --git a/packages/sdk-vue/package.json b/packages/sdk-vue/package.json index 37d5d29..4de241c 100644 --- a/packages/sdk-vue/package.json +++ b/packages/sdk-vue/package.json @@ -1,6 +1,6 @@ { "name": "@fusionauth/vue-sdk", - "version": "1.0.0", + "version": "1.0.1", "description": "FusionAuth solves the problem of building essential security without adding risk or distracting from your primary application", "type": "module", "scripts": { diff --git a/packages/sdk-vue/src/createFusionAuth/createFusionAuth.test.ts b/packages/sdk-vue/src/createFusionAuth/createFusionAuth.test.ts index 436f49a..a0ed264 100644 --- a/packages/sdk-vue/src/createFusionAuth/createFusionAuth.test.ts +++ b/packages/sdk-vue/src/createFusionAuth/createFusionAuth.test.ts @@ -70,6 +70,31 @@ describe('createFusionAuth', () => { expect(onRedirect).toHaveBeenCalledWith(expectedStateValue); }); + it('Invokes `onAutoRefreshFailure` with a helpful error when autorefresh fails', async () => { + vi.useFakeTimers(); + mockIsLoggedIn(); + + vi.spyOn(global, 'fetch').mockResolvedValueOnce( + new Response(JSON.stringify({ msg: 'could not refresh access token' }), { + status: 400, + }), + ); + + const onAutoRefreshFailure = vi.fn(); + + createFusionAuth({ + ...config, + shouldAutoRefresh: true, + onAutoRefreshFailure, + }); + + await vi.advanceTimersByTimeAsync(60 * 60 * 1000); + + expect(onAutoRefreshFailure).toHaveBeenCalledWith( + Error(JSON.stringify({ msg: 'could not refresh access token' })), + ); + }); + it('Can be configured to automatically refresh the access token', () => { mockIsLoggedIn(); vi.useFakeTimers(); @@ -113,7 +138,7 @@ describe('createFusionAuth', () => { expectedUrl.pathname = '/app/login'; expectedUrl.searchParams.set('client_id', config.clientId); expectedUrl.searchParams.set('redirect_uri', config.redirectUri); - expectedUrl.searchParams.set('scope', config.scope); + expectedUrl.searchParams.set('scope', config.scope!); expectedUrl.searchParams.set('state', stateValue); expect(mockedLocation.assign).toHaveBeenCalledWith(expectedUrl); @@ -130,7 +155,7 @@ describe('createFusionAuth', () => { expectedUrl.pathname = '/app/register'; expectedUrl.searchParams.set('client_id', config.clientId); expectedUrl.searchParams.set('redirect_uri', config.redirectUri); - expectedUrl.searchParams.set('scope', config.scope); + expectedUrl.searchParams.set('scope', config.scope!); expectedUrl.searchParams.set('state', stateValue); expect(mockedLocation.assign).toHaveBeenCalledWith(expectedUrl); diff --git a/packages/sdk-vue/src/types.ts b/packages/sdk-vue/src/types.ts index 208af9f..c536ffc 100644 --- a/packages/sdk-vue/src/types.ts +++ b/packages/sdk-vue/src/types.ts @@ -42,6 +42,11 @@ export interface FusionAuthConfig { */ onRedirect?: (state?: string) => void; + /** + * Callback to be invoked if a request to refresh the access token fails during autorefresh. + */ + onAutoRefreshFailure?: (error: Error) => void; + /** * The path to the login endpoint. */ @@ -133,7 +138,7 @@ export interface FusionAuth { * Refreshes the access token a single time. * Token refreshing is handled automatically if configured with `shouldAutoRefresh`. */ - refreshToken: () => Promise; + refreshToken: () => Promise; /** * Initializes automatic refreshing of the access token. diff --git a/packages/sdk-vue/web-types.json b/packages/sdk-vue/web-types.json index f7143bb..091ec1c 100644 --- a/packages/sdk-vue/web-types.json +++ b/packages/sdk-vue/web-types.json @@ -1,7 +1,7 @@ { "framework": "vue", "name": "@fusionauth/vue-sdk", - "version": "0.1.0", + "version": "1.0.1", "contributions": { "html": { "description-markup": "markdown", @@ -105,4 +105,4 @@ ] } } -} +} \ No newline at end of file