From 78c26c738ea20e13d9b4d6117298f98638d3d23d Mon Sep 17 00:00:00 2001 From: Valentina DOrazio Date: Wed, 3 Jul 2024 09:36:04 +0200 Subject: [PATCH 1/3] feat:add files BO02 --- src/pages/404.astro | 17 ++++++++++++++ src/pages/backoffice.astro | 46 ++++++++++++++++++++++++++++++++++++++ src/pages/index.astro | 2 ++ 3 files changed, 65 insertions(+) create mode 100644 src/pages/404.astro create mode 100644 src/pages/backoffice.astro diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..65212b0 --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,17 @@ +--- +import i18next, { changeLanguage } from "i18next"; +changeLanguage("en"); +--- + + + + 404 + + + + +
+

404

+
+ + \ No newline at end of file diff --git a/src/pages/backoffice.astro b/src/pages/backoffice.astro new file mode 100644 index 0000000..f6377c3 --- /dev/null +++ b/src/pages/backoffice.astro @@ -0,0 +1,46 @@ +--- +import { UserRecord, getAuth } from "firebase-admin/auth"; +import { app } from "../firebase/server"; +import i18next, { changeLanguage } from "i18next"; +import BackofficeLayout from "~/backoffice-layout/BackofficeLayout.astro"; + +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); + const pippo = { + email: "organizer@test.it", + displayName: "main organizer", + password: "verysecurepassword", + } + + //if the user is not an organizer redirect to 404.astro + if (!user?.customClaims?.organizer) { + Astro.response.status = 404; + Astro.response.statusText = "Not found"; + } +} + + +--- + + + + Backoffice + + + + +
+ +

Hi, you are in the backoffice world!

+

Put your content here!

+
+
+ + \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 96ce180..f76d7ab 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -38,6 +38,8 @@ if (sessionCookie) { )} + Login + {user?.customClaims?.organizer && Backoffice} \ No newline at end of file From 9803ed22c8728fcf8041cd039a52ae115e94e4cf Mon Sep 17 00:00:00 2001 From: Valentina DOrazio Date: Tue, 16 Jul 2024 11:14:11 +0200 Subject: [PATCH 2/3] feat: add fetch user --- src/backoffice-layout/BackofficeLayout.astro | 34 ++++++++++++++++---- src/pages/backoffice.astro | 7 ++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/backoffice-layout/BackofficeLayout.astro b/src/backoffice-layout/BackofficeLayout.astro index 49bf07d..be0add5 100644 --- a/src/backoffice-layout/BackofficeLayout.astro +++ b/src/backoffice-layout/BackofficeLayout.astro @@ -1,16 +1,38 @@ --- import Sidebar from "~/backoffice-layout/Sidebar.astro"; +//import { getUsers } from "../../functions/src/services/user"; +import { Debug } from "astro:components"; + /** * Backoffice Layout. How call this component? * *

My page content

*
*/ + +const sessionCookie = Astro.cookies.get("session")?.value; + +/* 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 ${sessionCookie}`} +}); +const data = await response.json(); + --- -
- - - -
- \ No newline at end of file +
+ + + + + +
diff --git a/src/pages/backoffice.astro b/src/pages/backoffice.astro index f6377c3..af60476 100644 --- a/src/pages/backoffice.astro +++ b/src/pages/backoffice.astro @@ -3,6 +3,8 @@ 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); @@ -11,11 +13,6 @@ let user: UserRecord | null = null; if (sessionCookie) { const decodedCookie = await auth.verifySessionCookie(sessionCookie); user = await auth.getUser(decodedCookie.uid); - const pippo = { - email: "organizer@test.it", - displayName: "main organizer", - password: "verysecurepassword", - } //if the user is not an organizer redirect to 404.astro if (!user?.customClaims?.organizer) { From 2352d32a954fb4ca6242d86b77f301dfe38ca864 Mon Sep 17 00:00:00 2001 From: Valentina DOrazio Date: Wed, 31 Jul 2024 09:40:48 +0200 Subject: [PATCH 3/3] feat: save work --- src/backoffice-layout/BackofficeLayout.astro | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backoffice-layout/BackofficeLayout.astro b/src/backoffice-layout/BackofficeLayout.astro index be0add5..131e818 100644 --- a/src/backoffice-layout/BackofficeLayout.astro +++ b/src/backoffice-layout/BackofficeLayout.astro @@ -2,6 +2,7 @@ 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? @@ -11,7 +12,7 @@ import { Debug } from "astro:components"; */ const sessionCookie = Astro.cookies.get("session")?.value; - +const token = await auth.currentUser?.getIdToken(); /* const aaa = JSON.stringify({ orderBy: "lastUpdate", offset: 0, @@ -23,7 +24,9 @@ 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();