-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
questionFurther information is requestedFurther information is requested
Description
I am checking if a user is logged in and if true then I am redirecting to the home page but the flash messages wont show
+page.server.ts
export const load: PageServerLoad = async ({ request, locals, cookies }) => {
if (locals.user && locals.session) {
// setFlash({ type: 'success', message: `Welcome ${locals.user.name} !` }, cookies) or
return redirect(303, "/", { type: 'error', message: 'You are already logged in.' }, cookies)
}
const form = await superValidate(request, zod(loginSchema))
return { form }
}
+layout.svelte
import { getFlash } from 'sveltekit-flash-message';
import { page } from '$app/stores';
import { toast } from 'svelte-sonner';
const flash = getFlash(page);
$: if ($flash) {
console.log('We have flash');
if ($flash.type === 'error') {
toast.error($flash?.message, {
action: {
label: 'X',
onClick: () => toast.dismiss()
},
duration: 3000
});
}
if ($flash.type === 'success') {
toast.success($flash.message, {
action: {
label: 'X',
onClick: () => toast.dismiss()
},
duration: 3000
});
}
}
Pascaltib
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested