Skip to content

Commit

Permalink
Merge pull request #237 from netlify/feat/add-jwt-refresh
Browse files Browse the repository at this point in the history
added refresh method from gotrue
  • Loading branch information
futuregerald authored May 4, 2020
2 parents 05152b1 + 2a0a7ba commit 5478207
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 5478207

Please sign in to comment.