Compare commits

..

11 Commits

Author SHA1 Message Date
Pilou
d537103ede Merge pull request #1588 from nhost/changeset-release/main
chore: update versions
2023-02-06 14:10:09 +01:00
github-actions[bot]
a27a45012f chore: update versions 2023-02-06 13:07:38 +00:00
Pilou
3a4f92be81 Merge pull request #1585 from nhost/fix/timers
exponential backoff
2023-02-06 14:06:11 +01:00
Pierre-Louis Mercereau
2c72f80c9f increase timeout again 2023-02-06 13:31:22 +01:00
Pierre-Louis Mercereau
25212e3651 increase timeout in cypress 2023-02-06 13:10:37 +01:00
Pierre-Louis Mercereau
82bb97f379 increase timeouts 2023-02-06 12:13:15 +01:00
Pierre-Louis Mercereau
d1ba284d94 increase intervals 2023-02-06 11:55:12 +01:00
Pierre-Louis Mercereau
75b913fc4f increase timeout 2023-02-06 10:53:12 +01:00
Pierre-Louis Mercereau
8e74cee080 remove only 2023-02-06 10:52:08 +01:00
Pierre-Louis Mercereau
9996acf824 pow 2023-02-06 10:24:46 +01:00
Pierre-Louis Mercereau
12ff631386 exponential backoff 2023-02-06 10:17:27 +01:00
22 changed files with 95 additions and 38 deletions

View File

@@ -1,5 +1,12 @@
# @nhost/dashboard
## 0.11.3
### Patch Changes
- @nhost/react-apollo@4.13.3
- @nhost/nextjs@1.13.3
## 0.11.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/dashboard",
"version": "0.11.2",
"version": "0.11.3",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",

View File

@@ -9,6 +9,8 @@ export default defineConfig({
mailHogUrl: 'http://127.0.0.1:8025',
env: {
backendUrl: 'http://localhost:1337'
}
},
defaultCommandTimeout: 20000,
requestTimeout: 20000
}
} as Cypress.ConfigOptions)

View File

@@ -1,5 +1,11 @@
# @nhost/apollo
## 4.13.2
### Patch Changes
- @nhost/nhost-js@1.13.2
## 4.13.1
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/apollo",
"version": "4.13.1",
"version": "4.13.2",
"description": "Nhost Apollo Client library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/react-apollo
## 4.13.3
### Patch Changes
- @nhost/apollo@4.13.2
- @nhost/react@1.13.3
## 4.13.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-apollo",
"version": "4.13.2",
"version": "4.13.3",
"description": "Nhost React Apollo client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/react-urql
## 1.0.3
### Patch Changes
- @nhost/react@1.13.3
## 1.0.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-urql",
"version": "1.0.2",
"version": "1.0.3",
"description": "Nhost React URQL client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,17 @@
# @nhost/hasura-auth-js
## 1.12.2
### Patch Changes
- 12ff6313: Set limits to refreshing the token on error
When starting, the client was trying to refresh the token five times every second, then indefinitely every five seconds.
It is now limited to 5 attempts at the following intervals: 5, 10, 20, 40, and 80 seconds. If all these attempts fail, the user state is signed out.
Similarly, when refreshing the token failed, the client was attempting to refresh the token every second.
It is now limited to 5 attempts at the following intervals: 5, 10, 20, 40, and 80 seconds.
## 1.12.1
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/hasura-auth-js",
"version": "1.12.1",
"version": "1.12.2",
"description": "Hasura-auth client",
"license": "MIT",
"keywords": [

View File

@@ -9,5 +9,4 @@ export const MIN_PASSWORD_LENGTH = 3
*/
export const TOKEN_REFRESH_MARGIN = 300 // five minutes
/** Number of seconds before retrying a token refresh after an error */
export const REFRESH_TOKEN_RETRY_INTERVAL = 5
export const REFRESH_TOKEN_MAX_ATTEMPTS = 5

View File

@@ -10,7 +10,7 @@ import { assign, createMachine, InterpreterFrom, send } from 'xstate'
import {
NHOST_JWT_EXPIRES_AT_KEY,
NHOST_REFRESH_TOKEN_KEY,
REFRESH_TOKEN_RETRY_INTERVAL,
REFRESH_TOKEN_MAX_ATTEMPTS,
TOKEN_REFRESH_MARGIN
} from '../../constants'
import {
@@ -331,19 +331,7 @@ export const createAuthMachine = ({
actions: ['saveSession', 'resetTimer', 'reportTokenChanged'],
target: 'pending'
},
onError: [
{ actions: 'saveRefreshAttempt', target: 'pending' }
// ? stop trying after x attempts?
// {
// actions: 'retry',
// cond: 'canRetry',
// target: 'pending'
// },
// {
// actions: ['sendError', 'resetToken'],
// target: '#timer.stopped'
// }
]
onError: [{ actions: 'saveRefreshAttempt', target: 'pending' }]
}
}
}
@@ -644,9 +632,13 @@ export const createAuthMachine = ({
return false
}
if (ctx.refreshTimer.lastAttempt) {
// * If a refesh previously failed, only try to refresh every `REFRESH_TOKEN_RETRY_INTERVAL` seconds
// * If the refresh timer reached the maximum number of attempts, we should not try again
if (ctx.refreshTimer.attempts > REFRESH_TOKEN_MAX_ATTEMPTS) {
return false
}
const elapsed = Date.now() - ctx.refreshTimer.lastAttempt.getTime()
return elapsed > REFRESH_TOKEN_RETRY_INTERVAL * 1_000
// * Exponential backoff
return elapsed > Math.pow(2, ctx.refreshTimer.attempts - 1) * 5_000
}
if (refreshIntervalTime) {
// * If a refreshIntervalTime has been passed on as an option, it will notify
@@ -663,9 +655,12 @@ export const createAuthMachine = ({
return remaining <= 0
},
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
/** Shoud retry to import the token on network error or any internal server error */
shouldRetryImportToken: (_, e: any) =>
e.data.error.status === NETWORK_ERROR_CODE || e.data.error.status >= 500,
/** Shoud retry to import the token on network error or any internal server error.
* Don't retry more than REFRESH_TOKEN_MAX_ATTEMPTS times.
*/
shouldRetryImportToken: (ctx, e: any) =>
ctx.importTokenAttempts < REFRESH_TOKEN_MAX_ATTEMPTS &&
(e.data.error.status === NETWORK_ERROR_CODE || e.data.error.status >= 500),
// * Authentication errors
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
unverified: (_, { data: { error } }: any) =>
@@ -924,10 +919,8 @@ export const createAuthMachine = ({
},
delays: {
RETRY_IMPORT_TOKEN_DELAY: ({ importTokenAttempts }) => {
if (importTokenAttempts < 5) {
return 1000
}
return 5000
// * Exponential backoff
return Math.pow(2, importTokenAttempts - 1) * 5_000
}
}
}

View File

@@ -471,7 +471,7 @@ describe(`Auto sign-in`, () => {
const state = await waitFor(authService, (state) => state.context.importTokenAttempts === 2)
expect(state.context.importTokenAttempts).toEqual(2)
})
}, 20000)
test(`should retry a token refresh if server returns an error`, async () => {
server.use(authTokenInternalErrorHandler)
@@ -486,7 +486,7 @@ describe(`Auto sign-in`, () => {
const state = await waitFor(authService, (state) => state.context.importTokenAttempts === 2)
expect(state.context.importTokenAttempts).toEqual(2)
})
}, 20000)
test(`should wait for the server to be online when starting offline`, async () => {
server.use(authTokenInternalErrorHandler)
@@ -511,7 +511,7 @@ describe(`Auto sign-in`, () => {
state.matches('authentication.signedIn')
)
expect(signedInState.context.user).not.toBeNull()
})
}, 20000)
test(`should automatically sign in if "refreshToken" was in the URL`, async () => {
vi.stubGlobal('location', {

View File

@@ -1,5 +1,11 @@
# @nhost/nextjs
## 1.13.3
### Patch Changes
- @nhost/react@1.13.3
## 1.13.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nextjs",
"version": "1.13.2",
"version": "1.13.3",
"description": "Nhost NextJS library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/nhost-js
## 1.13.2
### Patch Changes
- Updated dependencies [12ff6313]
- @nhost/hasura-auth-js@1.12.2
## 1.13.1
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nhost-js",
"version": "1.13.1",
"version": "1.13.2",
"description": "Nhost JavaScript SDK",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/react
## 1.13.3
### Patch Changes
- @nhost/nhost-js@1.13.2
## 1.13.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react",
"version": "1.13.2",
"version": "1.13.3",
"description": "Nhost React library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/vue
## 1.13.3
### Patch Changes
- @nhost/nhost-js@1.13.2
## 1.13.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/vue",
"version": "1.13.2",
"version": "1.13.3",
"description": "Nhost Vue library",
"license": "MIT",
"keywords": [