Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/backoffice-layout/BackofficeLayout.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
---
import Sidebar from "~/backoffice-layout/Sidebar.astro";
//import { getUsers } from "../../functions/src/services/user";
import { Debug } from "astro:components";
import { auth } from "~/firebase/client";

/**
* Backoffice Layout. How call this component?
* <BackofficeLayout>
* <p>My page content</p>
* </BackofficeLayout>
*/

const sessionCookie = Astro.cookies.get("session")?.value;
const token = await auth.currentUser?.getIdToken();
/* const aaa = JSON.stringify({
orderBy: "lastUpdate",
offset: 0,
limit: 2,
orderDirection: "desc",
}); */
const bbb = "orderBy=lastUpdate&offset=0&limit=2&orderDirection=desc";
const url =
"https://http-api-bu2cymxwrq-ey.a.run.app/user?" + bbb;
//new URLSearchParams(aaa);
const response = await fetch(url,{
//headers: {Authorization: `Bearer ${token}`}
headers: {Authorization: `Bearer ${sessionCookie}`}

});
const data = await response.json();

---

<div class="flex flex-row">
<Sidebar>
<slot/>
</Sidebar>
</div>

<div class="flex flex-row">
<Debug answer={data} />

<Sidebar>
<slot />
</Sidebar>
</div>
17 changes: 17 additions & 0 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
import i18next, { changeLanguage } from "i18next";
changeLanguage("en");
---

<html lang={i18next.language}>
<head>
<title>404</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Hedwig - 404" />
</head>
<body>
<main role="main">
<h1>404</h1>
</main>
</body>
</html>
43 changes: 43 additions & 0 deletions src/pages/backoffice.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
import { UserRecord, getAuth } from "firebase-admin/auth";
import { app } from "../firebase/server";
import i18next, { changeLanguage } from "i18next";
import BackofficeLayout from "~/backoffice-layout/BackofficeLayout.astro";
import { getUsers } from "../../functions/src/services/user";
import { Debug } from "astro:components";

changeLanguage("en");
const auth = getAuth(app);
const sessionCookie = Astro.cookies.get("session")?.value;
let user: UserRecord | null = null;
if (sessionCookie) {
const decodedCookie = await auth.verifySessionCookie(sessionCookie);
user = await auth.getUser(decodedCookie.uid);

//if the user is not an organizer redirect to 404.astro
if (!user?.customClaims?.organizer) {
Astro.response.status = 404;
Astro.response.statusText = "Not found";
}
}


---
<!-- This is the backoffice page, to add the link to this component
use {user?.customClaims?.organizer === true && <a href="/backoffice">Backoffice</a>}
in the page where the link should be visible -->
<html lang={i18next.language}>
<head>
<title>Backoffice</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Hedwig - Backoffice" />
</head>
<body>
<main role="main">
<BackofficeLayout>
<h1>Hi, you are in the backoffice world!</h1>
<p>Put your content here!</p>
</BackofficeLayout>
</main>
</body>
</html>
2 changes: 2 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if (sessionCookie) {
<button type="submit">Sign out</button>
</form>
)}
<a href="/signin">Login</a>
{user?.customClaims?.organizer && <a href="/backoffice">Backoffice</a>}
</main>
</body>
</html>