authentication in ssr (queryLoad)
See original GitHub issueHow 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 }) => {
kitQLClient.setHeaders(
session.token ? { Authorization: `Bearer ${session.token}` : {}
);
await sleep(3000);
console.log(kitQLClient.getHeaders());
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:
- Created a year ago
- Comments:23 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, you are right @david-plugge.
Will handle this in the next “big” version.
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.