|
| 1 | +# Migration from v3.x to v4.x |
| 2 | + |
| 3 | +When upgrading from v3 to v4, there are a few things to consider. |
| 4 | + |
| 5 | +## Changed method locations: |
| 6 | + |
| 7 | +- `cognito.restoreAndLoad()` remains the same; |
| 8 | +- `cognito.authenticate()` remains the same; |
| 9 | +- `cognito.authenticateUser()` --> `cognito.unauthenticated.verifyUserAuthentication()` |
| 10 | +- `cognito.logout()` --> remains the same |
| 11 | +- `cognito.invalidateAccessTokens()` --> remains the same |
| 12 | +- `cognito.triggerResetPasswordMail()` --> `cognito.unauthenticated.triggerResetPasswordMail()` |
| 13 | +- `cognito.updateResetPassword()` --> `cognito.unauthenticated.updateResetPassword()` |
| 14 | +- `cognito.setNewPassword()` --> `cognito.unauthenticated.setInitialPassword()` |
| 15 | +- `cognito.updatePassword()` --> `cognito.user.updatePassword()` |
| 16 | +- `cognito.updateAttributes()` --> `cognito.user.updateAttributes()` |
| 17 | +- `cognito.cognitoData.mfa` --> `cognito.user.mfa` |
| 18 | +- `cognito.cognitoData.cognitoUser` --> `cognito.user.cognitoUser` |
| 19 | +- `cognito.cognitoData.cognitoUserSession` --> `cognito.session.cognitoUserSession` |
| 20 | +- `cognito.cognitoData.jwtToken` --> `cognito.session.jwtToken` |
| 21 | +- `cognito.cognitoData.userAttributes` --> `cognito.user.userAttributes` |
| 22 | +- `cognito.cognitoData.getAccessToken()` --> `cognito.session.getAccessToken()` |
| 23 | +- `cognito.cognitoData.getIdToken()` --> `cognito.session.getIdToken()` |
| 24 | +- `cognito.refreshAccessToken()` --> `cognito.session.refresh()` |
| 25 | + |
| 26 | +## `cognitoData` is no more |
| 27 | + |
| 28 | +As you can see in the above section, `cognito.cognitoData` has been replaced with `cognito.user` and `cognito.session`. |
| 29 | + |
| 30 | +These two properties will be set when the user is authenticated, else they will be `undefined`. When `isAuthenticated === true` you can assume they are set. |
| 31 | + |
| 32 | +In contrast, `unauthenticated` is _always_ available. |
| 33 | + |
| 34 | +## Change token auto-refresh |
| 35 | + |
| 36 | +In 4.x, JWT tokens will _not_ be automatically refreshed when they expire. |
| 37 | +Instead, you can call `cognito.session.enableAutoRefresh()` and `cognito.session.disableAutoRefresh()` to start/stop the auto-refresh background job. |
| 38 | + |
| 39 | +There are also some new/changed methods to work with token refreshing: |
| 40 | + |
| 41 | +```js |
| 42 | +cognito.session.refresh(); |
| 43 | +cognito.session.refreshIfNeeded(); |
| 44 | +cognito.session.secondsUntilExpires(); |
| 45 | +cognito.session.needsRefresh(); |
| 46 | +cognito.session.needsRefreshSoon(); |
| 47 | +``` |
0 commit comments