Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom storage docs are contradictory #1687

Closed
MatteoGioioso opened this issue May 1, 2020 · 4 comments
Closed

Custom storage docs are contradictory #1687

MatteoGioioso opened this issue May 1, 2020 · 4 comments
Assignees
Labels
amplify/js Issues tied to JS

Comments

@MatteoGioioso
Copy link

Describe the bug
At this part of the docs on setting up Amplify

Amplify.configure({
    Auth: {

        // REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
        identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',

        // REQUIRED - Amazon Cognito Region
        region: 'XX-XXXX-X',

 
        // OPTIONAL - customized storage object
        storage: new MyStorage(),

    }
});

The description says: new MyStorage(),

However when it goes in details on how to override the storage property:
this is what is shown:

class MyStorage {
    // the promise returned from sync function
    static syncPromise = null;
    // set item with the key
    static setItem(key: string, value: string): string;
    // get item with the key
    static getItem(key: string): string;
    // remove item with the key
    static removeItem(key: string): void;
    // clear out the storage
    static clear(): void;
    // If the storage operations are async(i.e AsyncStorage)
    // Then you need to sync those items into the memory in this method
    static sync(): Promise<void> {
        if (!MyStorage.syncPromise) {
            MyStorage.syncPromise = new Promise((res, rej) => {});
        }
        return MyStorage.syncPromise;
    }
}

// tell Auth to use your storage object
Auth.configure({
    storage: MyStorage // <==== here
});

I have tested and the first one looks like is not working, however the second, without instantiating the class is working.

Could please someone clarify if this is wanted or a mistake?

Thanks

@mauerbac
Copy link
Member

mauerbac commented May 1, 2020

Hi @MatteoGioioso - thanks for reaching out. I'm going to move to our docs repo since this seems like a doc issue/question. cc @Brene

@mauerbac mauerbac transferred this issue from aws-amplify/amplify-js May 1, 2020
@renebrandel renebrandel added the amplify/js Issues tied to JS label May 1, 2020
@MatteoGioioso
Copy link
Author

MatteoGioioso commented May 3, 2020

@mauerbac sorry, didn't notice there was a repo for the docs

@cedricgrothues
Copy link
Contributor

cedricgrothues commented Jun 24, 2020

@MatteoGioioso – You're right. Auth checks if an object passed as a storage parameter is valid by using this function, which checks the type of required methods. Since all of the methods are static, this check does not work with an initialized class.

@ashika01
Copy link
Contributor

Hi, Closing this issue as the docs has been updated to reflect the right way of using this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify/js Issues tied to JS
Projects
None yet
Development

No branches or pull requests

6 participants