Previously, even if the authKey property was provided and a logged-in user was stored in localStorage, on first render the value of user was null. This was because the localStorageUserMiddleware which dispatches setUser to store the user in Redux had not yet been triggered.
This meant that previously if we tried to use the web component to view a project that the logged-in user owned, the request to editor-api to load the project would respond with a 403 Forbidden and the project would not load.
I'm fairly (but not completely) sure that the assertions in the "with user set in local storage" group of examples in
src/containers/WebComponentLoader.test.js were incorrect, i.e. if the authKey is set and a user is present in localStorage we ought to load the project based on the fact the user is logged in. I have fixed these assertions.
The null value of the user property in the call to useProjectPersistence in the "When no user is in state with no user in local storage" group of examples in src/containers/WebComponentLoader.test.js is due to the return value for localStorage.getItem(authKey) and not the fallback in the new ternary expression in WebComponentLoader. I think this is fine.
I'm not sure whether my fix is definitely correct/idiomatic - maybe I should be using a useState hook for the localStorageUser in combination with a useEffect hook...?
Also stepping back a bit, it's not entirely clear to me that dispatching setUser in localStorageUserMiddleware is definitely the most sensible place to do that.
Previously, even if the
authKey
property was provided and a logged-in user was stored inlocalStorage
, on first render the value ofuser
wasnull
. This was because thelocalStorageUserMiddleware
which dispatchessetUser
to store the user in Redux had not yet been triggered.This meant that previously if we tried to use the web component to view a project that the logged-in user owned, the request to editor-api to load the project would respond with a 403 Forbidden and the project would not load.
I'm fairly (but not completely) sure that the assertions in the "with user set in local storage" group of examples in
src/containers/WebComponentLoader.test.js
were incorrect, i.e. if theauthKey
is set and auser
is present inlocalStorage
we ought to load the project based on the fact the user is logged in. I have fixed these assertions.The
null
value of theuser
property in the call touseProjectPersistence
in the "When no user is in state with no user in local storage" group of examples insrc/containers/WebComponentLoader.test.js
is due to the return value forlocalStorage.getItem(authKey)
and not the fallback in the new ternary expression inWebComponentLoader
. I think this is fine.I'm not sure whether my fix is definitely correct/idiomatic - maybe I should be using a
useState
hook for thelocalStorageUser
in combination with auseEffect
hook...?Also stepping back a bit, it's not entirely clear to me that dispatching
setUser
inlocalStorageUserMiddleware
is definitely the most sensible place to do that.