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

Invalid URL in Non-Typescript Implementation #42

Open
Blue-Davinci opened this issue Jun 4, 2024 · 3 comments
Open

Invalid URL in Non-Typescript Implementation #42

Blue-Davinci opened this issue Jun 4, 2024 · 3 comments

Comments

@Blue-Davinci
Copy link

Blue-Davinci commented Jun 4, 2024

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`

@ciscoheat
Copy link
Owner

Hi, thank you, glad you like the library! It looks like you're not supplying the RequestEvent or Cookies in your redirect. Try this:

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

@Blue-Davinci
Copy link
Author

Hi, thank you, glad you like the library! It looks like you're not supplying the RequestEvent or Cookies in your redirect. Try this:

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

Hi, thank you, glad you like the library! It looks like you're not supplying the RequestEvent or Cookies in your redirect. Try this:

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

Thank you sir, worked properly. Have a blessed day.

@Blue-Davinci
Copy link
Author

I think my issue may now be similar to this: #38 as i am using the svelte cookie API without the append, as i cannot seem to get the flash message back after setting it.

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