-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Built-in method of refreshing session from server periodically #1726
Comments
I've thought about this and the design that @Rich-Harris sketched out in #46 (comment), and here's the design for session persistence and refreshing that I think would be best: Session persistence
Session refreshing
|
Example for this feature: Session cookie:
BUT! Out session store is not cleared until we refresh page! Because redirect from |
The only way to reactively change
Or to trigger SSR, which is worse solution. I wish |
BTW, @rmunn what is your opinion on refreshing |
Update the That could be as simple as const response = await fetch('/sign-out', {
method: 'POST'
});
$session = await response.json(); |
@babichjacob it is impossible, because
It would be such cool thing to update session server-side. I hope that we don't need then any methods to refresh/sync session client-side. |
@korywka Like the error suggests, you just have to wrap that <script context="module">
import { browser } from "$app/env";
import { session } from "$app/stores";
import { requestJSON } from "$lib/request.js";
/** @type {import('@sveltejs/kit').Load} */
export async function load({ fetch }) {
await requestJSON(fetch, "/auth/logout.json");
if (browser) session.set({ user: null });
return {
status: 302,
redirect: "/",
};
}
</script> When When |
@korywka I get the following error when trying to update the session in load... |
@Zachiah I was getting the same error, the error message is misleading. You're trying to update the global store that has nothing in it, you need the contextual one that is associated with your mounted component tree. As Google leads here, I'll post a solution/explanation that might help someone.
You have to either 1) use the session object that is passed into the load function (it's not a store, as this may have to run during SSR), 2) subscribe to the session store using the Also, I don't think you should be updating stores from within load, this might work on the client, even though it's the wrong store, but it will almost definitely leak user information during SSR when multiple requests are being handled. You should either take a look at the |
I did this. Not sure if it's the best solution but it works 🤷🏻♂️
|
This is probably moot now that #5946 has removed the special Meanwhile, the design I sketched out in #1726 (comment) can probably be implemented in user space now: create a handler to handle a |
In #1165 (comment), Rich Harris wrote:
This seems like a good idea, and it also seems to be a different feature than #1165 or #46. So I'm opening this issue to track discussion of a session-refresh feature, so this idea doesn't get lost. (I don't have any specific ideas for what the feature should look like, I'm just opening this issue so there's somewhere to discuss the idea, and hoping that other people will have a better idea of what they would want in a session-refresh feature).
The text was updated successfully, but these errors were encountered: