mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-09 12:57:48 +00:00
fix(tutorial): update redirect in SvelteKit SSR auth tutorial
The current redirect status code is 301, but that is a permanent redirect. The problem with this is the browser will cache the redirect and redirect for every request without even making a request to the server. Instead, we should use a 302 status code, which is a temporary redirect. So, when the user hits the home page, the browser will hit the server so that the server checks whether the user is logged in or not and redirect accordingly instead of always redirecting to the same page.
This commit is contained in:
@@ -51,7 +51,7 @@ export const actions = {
|
||||
});
|
||||
|
||||
// Redirect to the account page.
|
||||
redirect(301, "/account");
|
||||
redirect(302, "/account");
|
||||
},
|
||||
};
|
||||
```
|
||||
@@ -15,7 +15,7 @@ import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export async function load({ locals }) {
|
||||
// Logged out users can't access this page.
|
||||
if (!locals.user) redirect(301, "/signup");
|
||||
if (!locals.user) redirect(302, "/signup");
|
||||
|
||||
// Pass the stored user local to the page.
|
||||
return {
|
||||
@@ -34,7 +34,7 @@ export const actions = {
|
||||
event.cookies.delete(SESSION_COOKIE, { path: "/" });
|
||||
|
||||
// Redirect to the sign up page.
|
||||
redirect(301, "/signup");
|
||||
redirect(302, "/signup");
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
@@ -39,7 +39,7 @@ export const actions = {
|
||||
`${event.url.origin}/signup`
|
||||
);
|
||||
|
||||
redirect(301, redirectUrl);
|
||||
redirect(302, redirectUrl);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user