Skip to content
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

Flash not showing when redirecting from +layout.server.ts #10

Closed
erskingardner opened this issue Apr 27, 2023 · 5 comments
Closed

Flash not showing when redirecting from +layout.server.ts #10

erskingardner opened this issue Apr 27, 2023 · 5 comments

Comments

@erskingardner
Copy link

I'm having trouble getting flash messages to show after a redirect.

  1. I've set up my flash messages and when I manually provide a flash object in +layout.svelte I can see it show up.
  2. However, when I trigger the redirect in +layout.server.ts, which provides a flash message, the redirect happens fine but the flash message doesn't show up on the page.

Any help much appreciated.

+layout.server.ts

import type { LayoutServerLoad } from './$types';
import { loadFlashMessage } from 'sveltekit-flash-message/server';
import { get } from 'svelte/store';
import { currentUser } from '$lib/stores/currentUser';
import { redirect } from 'sveltekit-flash-message/server';

export const load = loadFlashMessage(async (event) => {
    const user = get(currentUser);

    if (!user && event.request.url.match('/new')) {
        const message = { type: 'error', message: 'You need to log in to create lists' } as const;
        throw redirect(303, '/', message, event);
    }
}) satisfies LayoutServerLoad;
@ciscoheat
Copy link
Owner

Hi, I'm trying to reproduce, but pretty much the exact same code works for me on the test suite. Can you check the cookies in the request and in the browser afterwards, if the flash cookie (called flash) is present after redirect? You may have to circumvent loadFlashMessage to test, since it deletes the cookie after extracting the data from it.

@ciscoheat
Copy link
Owner

Hopefully this will work in 1.0.0-rc.2, just released.

@erskingardner
Copy link
Author

I just updated and it doesn't seem to be any different. :/ I'll take another look through my code and see if there's something I'm doing wrong her.e

@ciscoheat
Copy link
Owner

It's still working for me, I'm happy to take a look at a MRE for it, if you cannot figure out what's wrong.

@ciscoheat
Copy link
Owner

Closing this since it's been about a month of inactivity. Feel free to open it again, or a new issue, if there still is a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants