Skip to content

Commit

Permalink
revert index
Browse files Browse the repository at this point in the history
  • Loading branch information
camillobucciarelli committed Aug 1, 2024
1 parent bbad727 commit 912a2eb
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,53 +1,43 @@
---
import i18next, { changeLanguage } from "i18next";
import { UserRecord, getAuth } from "firebase-admin/auth";
import { app } from "../firebase/server";
changeLanguage("en");
const auth = getAuth(app);
/* Check current session */
// if (!Astro.cookies.has("session")) {
// return Astro.redirect("/signin");
// }
const sessionCookie = Astro.cookies.get("session")?.value;
let user: UserRecord | null = null;
try {
const sessionCookie = Astro.cookies.get("session")?.value;
if (sessionCookie) {
const decodedCookie = await auth.verifySessionCookie(sessionCookie);
user = await auth.getUser(decodedCookie.uid);
if (!user) {
Astro.redirect("/signin");
}
}
} catch (error) {
Astro.redirect("/signin");
if (sessionCookie) {
const decodedCookie = await auth.verifySessionCookie(sessionCookie);
user = await auth.getUser(decodedCookie.uid);
}
---

<html lang={i18next.language}>
<head>
<title>Hedwig</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="A website template for Devfests, powered by GDG Pescara"
/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A website template for Devfests, powered by GDG Pescara">
</head>
<body>
<main role="main">
<h1>Welcome to Hedwig!</h1>
<p>We are happy to see you here</p>
{
user && (
<>
<h2>User logged: {user.displayName}</h2>
<form action="/api/auth/signout">
<button type="submit">Sign out</button>
</form>
</>
)
}
{user && (
<h2>User logged: {user.displayName}</h2>
<form action="/api/auth/signout">
<button type="submit">Sign out</button>
</form>
)}
</main>
</body>
</html>

0 comments on commit 912a2eb

Please sign in to comment.