Skip to content

added refresh method from gotrue #237

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

Merged
merged 2 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ netlifyIdentity.close();

// Log out the user
netlifyIdentity.logout();
// refresh the user's JWT
// Note: this method returns a promise.
netlifyIdentity.refresh().then((jwt)=>console.log(jwt))
```

#### A note on script tag versioning
Expand Down Expand Up @@ -113,6 +116,10 @@ netlifyIdentity.close();
// Log out the user
netlifyIdentity.logout();

// refresh the user's JWT
// Note: this method returns a promise.
netlifyIdentity.refresh().then((jwt)=>console.log(jwt))

// Access the underlying GoTrue JS client.
// Note that doing things directly through the GoTrue client brings a risk of getting out of
// sync between your state and the widget’s state.
Expand Down
6 changes: 6 additions & 0 deletions src/netlify-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const netlifyIdentity = {
}
return store.gotrue;
},
refresh(force) {
if (!store.gotrue) {
store.openModal("login");
}
return store.gotrue.currentUser().jwt(force);
},
init: options => {
init(options);
},
Expand Down