Skip to content

Commit 5478207

Browse files
authored
Merge pull request #237 from netlify/feat/add-jwt-refresh
added refresh method from gotrue
2 parents 05152b1 + 2a0a7ba commit 5478207

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ netlifyIdentity.close();
7171

7272
// Log out the user
7373
netlifyIdentity.logout();
74+
// refresh the user's JWT
75+
// Note: this method returns a promise.
76+
netlifyIdentity.refresh().then((jwt)=>console.log(jwt))
7477
```
7578

7679
#### A note on script tag versioning
@@ -113,6 +116,10 @@ netlifyIdentity.close();
113116
// Log out the user
114117
netlifyIdentity.logout();
115118

119+
// refresh the user's JWT
120+
// Note: this method returns a promise.
121+
netlifyIdentity.refresh().then((jwt)=>console.log(jwt))
122+
116123
// Access the underlying GoTrue JS client.
117124
// Note that doing things directly through the GoTrue client brings a risk of getting out of
118125
// sync between your state and the widget’s state.

src/netlify-identity.js

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const netlifyIdentity = {
4747
}
4848
return store.gotrue;
4949
},
50+
refresh(force) {
51+
if (!store.gotrue) {
52+
store.openModal("login");
53+
}
54+
return store.gotrue.currentUser().jwt(force);
55+
},
5056
init: options => {
5157
init(options);
5258
},

0 commit comments

Comments
 (0)