-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbad727
commit 912a2eb
Showing
1 changed file
with
16 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |