Skip to content

Setting a global custom storage to override all calls to localStorage #14340

Open
@kaestleo

Description

@kaestleo

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

Authentication

Is this related to another service?

No response

Describe the feature you'd like to request

Hi,

we are building a cross platform App based on Angular and Ionic Capacitor and have been using Cognito and Amplify for user management. Instead of using localStorage for any kind of user information, we have written a custom storage service based on Ionic's own storage.

In aws-amplify v5, we were able to use our custom storage by calling this.amplifyService.auth().configure({ storage: this.customStorageService });. As a result, all aws-amplify operations with respect to localStorage were redirected to our custom storage.

As far as I'm aware, in aws-amplify v6 it is possible to set a custom storage only for tokens by calling cognitoUserPoolsTokenProvider.setKeyValueStorage(this.customStorageService);.
(see https://docs.amplify.aws/angular/build-a-backend/auth/concepts/tokens-and-credentials/#update-your-token-saving-mechanism)

However, these are not equivalent implementations, since the user's identityId is still stored in the localStorage in v6. From what I have found, this is because the storage has been split up internally into an IdentityIdStore and a TokenStore, and the above code only overrides the usage of localStorage for the TokenStore.

I would like to kindly suggest an equivalent solution to the custom storage implementation of v5, such that all storage operations defaulting to localStorage can be overriden with a custom storage.

Thank you for your time and your ongoing work on this project.

Describe the solution you'd like

An easy solution would be to add a setKeyValueStorage(keyValueStorage: KeyValueStorageInterface) method for cognitoCredentialsProvider, analogous to the existing implementation for cognitoUserPoolsTokenProvider.

Describe alternatives you've considered

I feel that it would be even more preferable to implement a single method to set a global custom storage, replacing localStorage wherever it is called inside aws-amplify v6.

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthRelated to Auth components/categoryfeature-requestRequest a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions