Skip to content

Commit dd6f535

Browse files
committed
wrapped request refresh jwt hook with memoize
1 parent 57c1e5d commit dd6f535

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

dash/dash-renderer/src/AppContainer.react.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Loading from './components/core/Loading.react';
66
import Toolbar from './components/core/Toolbar.react';
77
import Reloader from './components/core/Reloader.react';
88
import {setHooks, setConfig} from './actions/index';
9-
import {type} from 'ramda';
9+
import {type, memoizeWith, identity} from 'ramda';
1010

1111
class UnconnectedAppContainer extends React.Component {
1212
constructor(props) {
@@ -16,6 +16,12 @@ class UnconnectedAppContainer extends React.Component {
1616
props.hooks.request_post !== null ||
1717
props.hooks.request_refresh_jwt !== null
1818
) {
19+
if (props.hooks.request_refresh_jwt) {
20+
props.hooks.request_refresh_jwt = memoizeWith(
21+
identity,
22+
props.hooks.request_refresh_jwt
23+
);
24+
}
1925
props.dispatch(setHooks(props.hooks));
2026
}
2127
}

tests/integration/renderer/test_request_hooks.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def update_output(value):
189189

190190
dash_duo.percy_snapshot(name="request-hooks interpolated")
191191

192+
192193
def test_rdrh003_refresh_jwt(dash_duo):
193194

194195
app = Dash(__name__)
@@ -225,18 +226,10 @@ def test_rdrh003_refresh_jwt(dash_duo):
225226
</body>
226227
</html>"""
227228

228-
229229
app.layout = html.Div(
230230
[
231231
dcc.Input(id="input", value="initial value"),
232-
html.Div(
233-
html.Div(
234-
[
235-
html.Div(id="output-1"),
236-
html.Div(id="output-token")
237-
]
238-
)
239-
),
232+
html.Div(html.Div([html.Div(id="output-1"), html.Div(id="output-token")])),
240233
]
241234
)
242235

@@ -251,18 +244,21 @@ def protect_route(func):
251244
@functools.wraps(func)
252245
def wrap(*args, **kwargs):
253246
try:
254-
if flask.request.method == 'OPTIONS':
247+
if flask.request.method == "OPTIONS":
255248
return func(*args, **kwargs)
256-
token = flask.request.authorization or flask.request.headers.environ.get(
257-
"HTTP_AUTHORIZATION"
249+
token = (
250+
flask.request.authorization
251+
or flask.request.headers.environ.get("HTTP_AUTHORIZATION")
258252
)
259-
if required_jwt_len and (not token or len(token) != required_jwt_len + len('Bearer ')):
253+
if required_jwt_len and (
254+
not token or len(token) != required_jwt_len + len("Bearer ")
255+
):
260256
flask.abort(401, description="JWT Expired " + str(token))
261257
except HTTPException as e:
262258
return e
263259
return func(*args, **kwargs)
264-
return wrap
265260

261+
return wrap
266262

267263
# wrap all API calls with auth.
268264
for name, method in (

0 commit comments

Comments
 (0)