Back

[SOLVED] Sveltekit: Throw Redirect in Promise Error (+page.server.ts)

  • 0
  • Self Hosted
  • Web
josephmbau
18 Jun, 2023, 21:55

After getting the user/client's session object in the Sveltekit Server I am trying to take the user/client from sign in page to the main page using throw redirect. I keep getting unhandled error. What should I do? Thanks in advance.

TL;DR
The user is trying to use SSR functionality on localhost without a DNS record. They are looking to switch to another page using Sveltekit actions and throw redirect. The issue seems to be that throw redirect only works in hooks and not in form actions. The user is also encountering an unhandled error when trying to use throw redirect to navigate from the sign-in page to the main page. There is a suggestion to try using throw redirect inside a try-catch block in the sign_in function.
Deleted User
18 Jun, 2023, 22:03

Why do you throw?

TypeScript
throw redirect(303, "/")

On success?

Deleted User
18 Jun, 2023, 22:03

Throw inside then() will move you to the catch part.

josephmbau
18 Jun, 2023, 22:11

sorry i did not understand you there (edited) Replying to asfaswrefarfga ON

Send a message in "Sveltekit: Throw Redirect in Promise Error (+page.server.ts)"

Deleted User
18 Jun, 2023, 22:11
Deleted User
18 Jun, 2023, 22:11

This line

Deleted User
18 Jun, 2023, 22:12

Why you throw?

josephmbau
18 Jun, 2023, 22:13

To take the client from the sign in page to the home page

Deleted User
18 Jun, 2023, 22:16

Ohh I see But the problem is that you're inside a then code So try to this

TypeScript
 export async function sign_in(signInObjectArg:any) {
  let isLoggedIn = false;
  try {
    await account.createEmailSession(signInObjectArg.email, signInObjectArg.password);
    isLoggednIn = true;
  } catch (e) {
    console.log(e); // Failure
  }

  if(isLoggedIn) { 
    throw redirect(303, "/")
  }

}
josephmbau
18 Jun, 2023, 22:24

this doesnt solve it, same error.

Deleted User
18 Jun, 2023, 22:25

You removed the then and you still get the without catch block?

Deleted User
18 Jun, 2023, 22:25

Maybe you run the sign_in inside another then() function?

Meldiron
19 Jun, 2023, 11:13

Sessions can't work properly out of the box with server-side-rendering. This is because Appwrite APIs use cookies to authorize. To have proper SSR integration with Appwrite, you will need to proxy some requests. You can check out this demo and it's GitHub repository to learn more: https://svelte-kit.ssr.almostapps.eu/

josephmbau
19 Jun, 2023, 12:04

how can i switch to another page using sveltekit actions and throw redirect? seems to be working only in hooks, but not form actions

josephmbau
19 Jun, 2023, 16:21
josephmbau
19 Jun, 2023, 16:24

[SOLVED] Sveltekit: Throw Redirect in Promise Error (+page.server.ts)

Super_Nove
2 Aug, 2023, 16:28

Hi, I am trying to use the solution provides in the example "almostSSR". I'am new to Appwrite (switching from Supabase). My Question: Is it possible to use this SSR functionality on localhost? At the moment I don't have an DNS Record and for developing i want to work on my Laptop. I am talking about these configs in $lib/AppwriteService.ts.

TypeScript
export const SsrHostname: string = 'svelte-kit.ssr.almostapps.eu';
export const AppwriteHostname: string = 'appwrite.svelte-kit.ssr.almostapps.eu';
Drake
2 Aug, 2023, 16:46

please create a new post instead of posting in an old thread 🙏🏼

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more