diff --git a/src/backoffice-layout/BackofficeLayout.astro b/src/backoffice-layout/BackofficeLayout.astro index 49bf07d..131e818 100644 --- a/src/backoffice-layout/BackofficeLayout.astro +++ b/src/backoffice-layout/BackofficeLayout.astro @@ -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? * *

My page content

*
*/ + +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(); + --- -
- - - -
- \ No newline at end of file +
+ + + + + +
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..af60476 --- /dev/null +++ b/src/pages/backoffice.astro @@ -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"; + } +} + + +--- + + + + 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