Skip to content

Commit

Permalink
Exclude home page from SSR to fix connected flash (#398)
Browse files Browse the repository at this point in the history
Exclude home page from SSR
  • Loading branch information
florimondmanca committed Aug 31, 2022
1 parent 9425bed commit 50354cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions client/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { DataFormat, UpdateFrequency } from "./definitions/datasets";

// Note : the / page (the home page) is "semi public". This page layout and information displayed depends whether the user is connected or not
export const PUBLIC_PAGES = [
export const STATIC_PAGES = [
"/login",
"/",
"/auth/datapass/create-organization",
"/auth/datapass/login",
];
Expand Down
7 changes: 4 additions & 3 deletions client/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Handle } from "@sveltejs/kit";
import { maybePatchDataUrl } from "$lib/fetch";
import { PUBLIC_PAGES } from "./constants";
import { STATIC_PAGES } from "./constants";

// See: https://kit.svelte.dev/docs/hooks#handle
export const handle: Handle = async ({ event, resolve }) => {
let response = await resolve(event, {
// NOTE: SSR usage is aimed at improving SEO, so we focus on public pages.
// NOTE: SSR usage is aimed at improving SEO, so we focus on static pages
// that do not depend on user authentication.
// This also happens to simplify the e2e test setup, as auth state
// for private pages can then be exclusively managed in the browser.
// See: https://github.com/etalab/catalogage-donnees/pull/143
ssr: PUBLIC_PAGES.includes(event.url.pathname),
ssr: STATIC_PAGES.includes(event.url.pathname),
});

response = await maybePatchDataUrl(response, event.url);
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib/auth/guard.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { get } from "svelte/store";
import type { LoadOutput } from "@sveltejs/kit";
import { user } from "../stores/auth";
import { PUBLIC_PAGES } from "src/constants";
import { STATIC_PAGES } from "src/constants";
import { Maybe } from "$lib/util/maybe";

/**
* Force-redirect to the login page if an unauthenticated user
* is attempting to access a protected page.
*/
export const authGuard = (url: URL): LoadOutput => {
if (PUBLIC_PAGES.includes(url.pathname)) {
if (STATIC_PAGES.includes(url.pathname)) {
return {};
}

Expand Down

0 comments on commit 50354cd

Please sign in to comment.