sveltekit-flash-message icon indicating copy to clipboard operation
sveltekit-flash-message copied to clipboard

Invalid URL in Non-Typescript Implementation

Open Blue-Davinci opened this issue 1 year ago • 3 comments

Hello Mr.Cisco, First of all thank you for the amazing library and I got pointed to it via a video from HuntaByte. Anyway the main issue is that am receiving an "Invalid URL" error which seems to stem from the redirect. Here is my current simple setup: "@sveltejs/adapter-auto": "^3.0.0", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", I am using a hook.server.js that reads a cookie and sets an event.locals My layout.server.js is also wrapped in the loadFlash as shown below:

`import { loadFlash } from 'sveltekit-flash-message/server';

export const load = loadFlash(async({locals}) =>{ let user = locals.user; console.log("[Layout.server.js ROOT] User:",user); return{ props: { user } } });`

After that I have setup a simple if and div in the main home layout.svelte, but the issue comes up in my login page.server.js, where am using the redirect to redirect and send a flash after a succesful login. Below is a snippet `import {fail} from '@sveltejs/kit'; import {z} from 'zod'; import { redirect } from 'sveltekit-flash-message/server';

login: async({fetch, request, url}) => {
              .....
          redirect('/', {type: 'success', message: 'Login Successful'});

} On the redirect it breaks and throws an invalid url, Not even using an absolute url like: http://localhost:5000/, still yields the same:TypeError: Invalid URL`

Blue-Davinci avatar Jun 04 '24 09:06 Blue-Davinci