Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Refactor cognitoData to dedicated user/session objects #773

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Aug 23, 2022

This splits the functionality/methods up a bit more.

This is a BREAKING CHANGE as it moves the methods around quite a bit. However, migration should be pretty mechanical, doable with search-and-replace:

Changed method locations:

  • cognito.restoreAndLoad() remains the same;
  • cognito.authenticate() remains the same;
  • cognito.authenticateUser() --> cognito.unauthenticated.verifyUserAuthentication()
  • cognito.logout() --> remains the same
  • cognito.invalidateAccessTokens() --> remains the same
  • cognito.triggerResetPasswordMail() --> cognito.unauthenticated.triggerResetPasswordMail()
  • cognito.updateResetPassword() --> cognito.unauthenticated.updateResetPassword()
  • cognito.setNewPassword() --> cognito.unauthenticated.setInitialPassword()
  • cognito.updatePassword() --> cognito.user.updatePassword()
  • cognito.updateAttributes() --> cognito.user.updateAttributes()
  • cognito.cognitoData.mfa --> cognito.user.mfa
  • cognito.cognitoData.cognitoUser --> cognito.user.cognitoUser
  • cognito.cognitoData.cognitoUserSession --> cognito.session.cognitoUserSession
  • cognito.cognitoData.jwtToken --> cognito.session.jwtToken
  • cognito.cognitoData.userAttributes --> cognito.user.userAttributes
  • cognito.cognitoData.getAccessToken() --> cognito.session.getAccessToken()
  • cognito.cognitoData.getIdToken() --> cognito.session.getIdToken()
  • cognito.refreshAccessToken() --> cognito.session.refresh()

cognitoData is no more

As you can see in the above section, cognito.cognitoData has been replaced with cognito.user and cognito.session.

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.

In contrast, unauthenticated is always available.

Change token auto-refresh

In 4.x, JWT tokens will not be automatically refreshed when they expire.
Instead, you can call cognito.session.enableAutoRefresh() and cognito.session.disableAutoRefresh() to start/stop the auto-refresh background job.

There are also some new/changed methods to work with token refreshing:

cognito.session.refresh();
cognito.session.refreshIfNeeded();
cognito.session.secondsUntilExpires();
cognito.session.needsRefresh();
cognito.session.needsRefreshSoon();

Other changes/news

This also drops the ember-concurrency dependency.

@mydea mydea added the enhancement New feature or request label Aug 23, 2022
@mydea mydea self-assigned this Aug 23, 2022
@mydea mydea changed the title feat: Refactor cognitoData to dedicated user/session objects Refactor cognitoData to dedicated user/session objects Aug 23, 2022
@mydea mydea force-pushed the fn/improve-session-refresh branch 2 times, most recently from 68b1bdb to 6dc5b8e Compare August 23, 2022 14:41
This splits the functionality/methods up a bit more.

BREAKING CHANGE: Moves method definitions/locations around a bit.
@mydea mydea force-pushed the fn/improve-session-refresh branch from 6dc5b8e to d539558 Compare August 23, 2022 14:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant