edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

@gel/auth-sveltekit with redirect Error & solution

Open lonexw opened this issue 8 months ago • 2 comments

This issue primarily helps users of @gel/auth-sveltekit with the latest Svelte 5 version, where they may encounter a problem with the built-in Auth UI failing to redirect in preview or production environments:

Error: {"status":307,"location":"http://localhost:10708/db/main/ext/auth/ui/signin?challenge=jkG6CY6kq4y2FzbrJpVM9dN1qPIOG1lQMtmxSoDk-3c"}

The root cause is that SvelteKit cannot determine whether this thrown error is of the Redirect type. For reference: https://svelte.dev/docs/kit/@sveltejs-kit#isRedirect.

As a temporary workaround, you can consider locally importing the entire package and converting it to a TypeScript file. This will resolve the issue for now and also allow you to customize additional logic more easily.

Image

Hope this saves others some time if they run into the same problem! 希望遇到同样问题的朋友可以少花时间在这里~

lonexw avatar Apr 02 '25 09:04 lonexw

The root cause is that SvelteKit cannot determine whether this thrown error is of the Redirect type.

Do you know how we should actually fix this? Why can't SvelteKit tell if the redirect was thrown from redirect?

scotttrinh avatar Apr 02 '25 12:04 scotttrinh

This appears to be related to type checking logic - in Svelte, redirect is treated as a special kind of exception for inspection purposes.

} catch (e) {
  // check redirect throw
  if (e instanceof Redirect) {
    const response = is_data_request ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
    add_cookies_to_headers(response.headers, Object.values(new_cookies));
    return response;
  }
  return await handle_fatal_error(event, options2, e);
}

The current issue is quite peculiar – when I import the file as a standalone TypeScript file, the problem doesn't occur. This might be related to the Svelte or SvelteKit version? I've tried debugging it in my local deployment environment, but still haven't figured out how to fix it within the npm package.

lonexw avatar Apr 02 '25 17:04 lonexw