Skip to content

Commit

Permalink
fix: call access token expiration watcher on access token change (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Feb 15, 2022
1 parent 32ac32d commit 5e2229d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -39,6 +39,7 @@
"jose": "4.3.7",
"jwt-decode": "3.1.2",
"ky": "0.28.7",
"lodash.debounce": "4.0.8",
"ramda": "0.27.1"
},
"devDependencies": {
Expand All @@ -50,6 +51,7 @@
"@testing-library/react-hooks": "7.0.2",
"@types/bcryptjs": "2.4.2",
"@types/jest": "27.4.0",
"@types/lodash.debounce": "4.0.6",
"@types/node": "17.0.6",
"@types/ramda": "0.27.62",
"@types/react": "17.0.38",
Expand Down
5 changes: 3 additions & 2 deletions src/AuthProvider/index.tsx
@@ -1,6 +1,7 @@
/* eslint-env browser, node */

import ky, { HTTPError } from 'ky'
import debounce from 'lodash.debounce'
import { useRouter } from 'next/router.js'
import React from 'react'

Expand Down Expand Up @@ -266,7 +267,7 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({ children, Loader,
return {
logIn,
logOut,
refresh,
refresh: debounce(refresh, 5000) as AuthContext['refresh'],
signUp,
state,
user,
Expand Down Expand Up @@ -300,7 +301,7 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({ children, Loader,

React.useEffect(() => {
watchAccessTokenExpiration()
}, [$accessTokenExpirationTimestamp.current])
}, [providerValue.state.accessToken])

if (isPrivatePath && state.isLoading) {
return <Loader />
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Expand Up @@ -1505,6 +1505,18 @@
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/lodash.debounce@4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@types/lodash.debounce/-/lodash.debounce-4.0.6.tgz#c5a2326cd3efc46566c47e4c0aa248dc0ee57d60"
integrity sha512-4WTmnnhCfDvvuLMaF3KV4Qfki93KebocUF45msxhYyjMttZDQYzHkO639ohhk8+oco2cluAFL3t5+Jn4mleylQ==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.178"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==

"@types/minimist@^1.2.0":
version "1.2.2"
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz"
Expand Down Expand Up @@ -5458,6 +5470,11 @@ lodash.capitalize@^4.2.1:
resolved "https://registry.yarnpkg.com/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz#f826c9b4e2a8511d84e3aca29db05e1a4f3b72a9"
integrity sha1-+CbJtOKoUR2E46yinbBeGk87cqk=

lodash.debounce@4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash.escaperegexp@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347"
Expand Down

0 comments on commit 5e2229d

Please sign in to comment.