How to read/write a store from client and server, now that Load.session has been removed. #6456
-
I develop an external backend that the client-side and server-side of my SvelteKit app send requests to. These requests require a header with an For these reasons I need to be able to read/write this access token value before sending any request, which may happen at either client or server. Below are some approaches I tried:
In approach 1, on the client side, how could I update the access token for all future client/server requests? Dropdown to see what the second approach would look like this in my load functions
Note: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
According to Rich Harris, it seems like the only way to update the client-side is also to use invalidate and cause load functions to re-run. There is no way to directly update values in
I was using cookie-based authentication to fetch access tokens. And, I came to two very important realizations:
Explanations:
TLDR:Since all my requests to get a new access token from the server-side would fail with "Unauthorized," I realized that approach 1 was impossible. As an alternative, I could refresh access tokens in This approach has the same benefits as my original second approach. The second approach is better as using stores feels much more natural than Footnotes
|
Beta Was this translation helpful? Give feedback.
According to Rich Harris, it seems like the only way to update the client-side is also to use invalidate and cause load functions to re-run. There is no way to directly update values in
$page.data
.I was using cookie-based authentication to fetch access tokens. And, I came to two very important realizations:
Explanations: