Is there a way to propagate redirects through sequenced Handle hooks? #10754
-
I have my server-session and authentication handles in 3 different functions. They are sequenced with the sequence helper. As simplified examples:
The problem is that my auth Handle function needs to redirect sometimes. I can't seem to make it to the third function if I redirect in any way. It is preventing me from storing my state/nonce/returnTo session variables before the request ends. In the auth Handle, I've tried I could probably pass a message to the third Handle to tell it to redirect, but I'm trying to keep all the session and auth logic separate while making use of existing features. I could probably pass a Can someone please point me in the right direction? Am I abusing sequence? Am I missing something obvious? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You probably want to rethink about how you implemented your const load = async ({ resolve, event }) => {
const sid = event.cookies.get("myauthcookie");
// load the state
event.locals = redisGetAndParse(sid);
// sveltekit stuff
const response = await resolve(event);
// response may be a redirect but we don´t really care
// we just want to do some stuff after the request is created
// save the state
redisStringifyAndSet(sid, event.locals);
return response;
} |
Beta Was this translation helpful? Give feedback.
-
You can try |
Beta Was this translation helpful? Give feedback.
You probably want to rethink about how you implemented your
load
andsave
handle hooks.To me it looks like you want to populate
locals
before sveltekit does it´s stuff and save the state to redis when its done.If that is the case, you can (and should) combine the logic into a single handle hook: