Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

authentication in ssr (queryLoad)

See original GitHub issue

How do i authenticate requests on the server side in sveltekit´s load function?

Using the setHeaders method overrides the global headers so parallel requests may be incorrectly authenticated.

// src/routes/__layout.svelte
export const load: Load = async ({ session, fetch }) => {

		session.token ? { Authorization: `Bearer ${session.token}` : {}

	await sleep(3000);


	return {};

When two clients connect within 3 seconds and only one is logged in, the second requests authentication state is used for the first request aswell.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

jycouetcommented, May 20, 2022

Yes, you are right @david-plugge.

Will handle this in the next “big” version.

jycouetcommented, May 11, 2022

I’m in a big refactoring for even a better accelerator 😉 And for sure, I will add a dedicated page in the doc on this topic showing different options available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering: how to serve authenticated content
What is server-side rendering? Learn how it works when dealing with authenticated users to render the correct content.
Read more >
Next.js SSR authentication with Clerk
Clerk allows you to verify a user is authenticated and to retrieve user profile data when using SSR. Below, we will cover how...
Read more >
How to implement authentication for SSR pages & API routes ...
Sever-side and API route authentication is a critical aspect of full-stack Next.js applications. You can protect SSR pages and API routes using NextAuth.js....
Read more >
Server-Side Rendering - Supabase
Single-page apps with server-side rendering (SSR) is a popular way to optimize rendering performance and leverage advanced caching strategies. Supabase Auth ...
Read more >
How to authenticate user on SSR? - Elixir Forum
In CSR we usually pass token with the request for backend verification, and we do this process by extracting the token from localStorage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found