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

Android refresh method #314

Merged
merged 6 commits into from
Oct 20, 2023
Merged

Conversation

CaolanCode
Copy link
Contributor

@CaolanCode CaolanCode commented Oct 18, 2023

Hi,

Thanks for you work on the plugin. It's awesome.

I've created a refresh function to return the accessToken and idToken for Android users.
Both IOS and Web have working refresh methods.
Can you guide me to what documentation you like me to contribute for this commit?

@reslear
Copy link
Collaborator

reslear commented Oct 19, 2023

write about refresh method, and how to use

@CaolanCode
Copy link
Contributor Author

CaolanCode commented Oct 20, 2023

Android Refresh Method

This method should be called when the app is initialized to establish if the user is currently logged in. If true, the method will return an accessToken, idToken and an empty refreshToken. It has the same functionality as the web refresh method.

Example

  initializeApp() {
    this.platform.ready().then(() => {
      this.checkLoggedIn();
    });
  }
  checkLoggedIn() {
    GoogleAuth.refresh()
      .then((data) => {
        if (data.accessToken) {
          this.currentToken = data;
          const storedUser = localStorage.getItem('user');
          if (storedUser) {
            this.user = JSON.parse(storedUser);
          }
        }
      })
      .catch((error) => {
        if (error.type === 'userLoggedOut') {
          this.signin();
        }
      });
  }

@CaolanCode CaolanCode changed the title Android refresh function Android refresh method Oct 20, 2023
@reslear
Copy link
Collaborator

reslear commented Oct 20, 2023

@CaolanCode
Copy link
Contributor Author

Will do.

@CaolanCode
Copy link
Contributor Author

I've submitted the documentation to the README.md

@reslear reslear merged commit e5975f3 into CodetrixStudio:master Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants