chore: use updated api which has optional protobuf support
Brijesh Wawdhane ops@brijesh.dev
Thu, 19 Dec 2024 19:54:02 +0530
8 files changed,
97 insertions(+),
87 deletions(-)
D
README.md
@@ -1,36 +0,0 @@
-This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). - -## Getting Started - -First, run the development server: - -```bash -npm run dev -# or -yarn dev -# or -pnpm dev -# or -bun dev -``` - -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. - -You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file. - -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. - -## Learn More - -To learn more about Next.js, take a look at the following resources: - -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! - -## Deploy on Vercel - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. - -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
M
src/app/(auth)/layout.js
→
src/app/(auth)/layout.js
@@ -13,12 +13,19 @@ try {
// Check if token exists in localStorage const token = localStorage.getItem("token"); if (token) { - // Verify token by making a request to /auth/me - const response = await fetch("http://localhost:8080/auth/me", { - headers: { - Authorization: `Bearer ${token}`, + // Verify token by making a request to /twirp/auth.AuthService/ValidateToken + const response = await fetch( + "http://localhost:8080/twirp/auth.AuthService/ValidateToken", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + token: token, + }), }, - }); + ); if (response.ok) { // Token is valid, redirect to dashboard
M
src/app/actions/auth.js
→
src/app/actions/auth.js
@@ -2,16 +2,19 @@ "use server";
export async function login(formData) { try { - const response = await fetch("http://localhost:8080/auth/login", { - method: "POST", - headers: { - "Content-Type": "application/json", + const response = await fetch( + "http://localhost:8080/twirp/auth.AuthService/Login", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email: formData.get("email"), + password: formData.get("password"), + }), }, - body: JSON.stringify({ - email: formData.get("email"), - password: formData.get("password"), - }), - }); + ); if (!response.ok) { throw new Error("Login failed");@@ -23,31 +26,35 @@ // Note: We'll need to handle token storage on the client side
// as we can't access localStorage from server actions return { success: true, data }; } catch (error) { + console.error("Login error:", error); return { success: false, error: "Invalid credentials" }; } } export async function register(formData) { try { - const response = await fetch("http://localhost:8080/auth/register", { - method: "POST", - headers: { - "Content-Type": "application/json", + const response = await fetch( + "http://localhost:8080/twirp/auth.AuthService/Register", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email: formData.get("email"), + password: formData.get("password"), + }), }, - body: JSON.stringify({ - email: formData.get("email"), - password: formData.get("password"), - }), - }); + ); if (!response.ok) { - const errorText = await response.text(); throw new Error("Registration failed"); } const data = await response.json(); return { success: true, data }; } catch (error) { + console.error("Registration error:", error); return { success: false, error: "Registration failed " + error }; } }
M
src/app/dashboard/api-keys/new/page.js
→
src/app/dashboard/api-keys/new/page.js
@@ -18,14 +18,17 @@ setIsSubmitting(true);
setError(""); try { - const response = await fetch("http://localhost:8080/api-keys", { - method: "POST", - headers: { - Authorization: `Bearer ${localStorage.getItem("token")}`, - "Content-Type": "application/json", + const response = await fetch( + "http://localhost:8080/twirp/apikeys.APIKeysService/CreateAPIKey", + { + method: "POST", + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ name }), }, - body: JSON.stringify({ name }), - }); + ); if (!response.ok) throw new Error("Failed to create API key");
M
src/app/dashboard/api-keys/page.js
→
src/app/dashboard/api-keys/page.js
@@ -15,11 +15,14 @@ }, []);
async function fetchAPIKeys() { try { - const response = await fetch("http://localhost:8080/api-keys", { - headers: { - Authorization: `Bearer ${localStorage.getItem("token")}`, + const response = await fetch( + "http://localhost:8080/twirp/apikeys.APIKeysService/ListAPIKeys", + { + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, }, - }); + ); if (!response.ok) throw new Error("Failed to fetch API keys");@@ -59,12 +62,17 @@ return;
} try { - const response = await fetch(`http://localhost:8080/api-keys/${keyId}`, { - method: "DELETE", - headers: { - Authorization: `Bearer ${localStorage.getItem("token")}`, + const response = await fetch( + `http://localhost:8080/twirp/apikeys.APIKeysService/RevokeAPIKey`, + { + method: "POST", + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ keyId }), }, - }); + ); if (!response.ok) throw new Error("Failed to revoke API key");@@ -75,7 +83,7 @@ console.error("Error:", error);
} } - if (!apiKeys) { + if (!apiKeys.length) { return ( <div className="rounded-lg bg-white shadow"> <div className="px-4 py-12 my-0">
M
src/app/globals.css
→
src/app/globals.css
@@ -1,3 +1,14 @@
@tailwind base; @tailwind components; @tailwind utilities; + +.overlay { + position: fixed; /* Fix the overlay to the screen */ + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black */ + z-index: 9999; /* Ensure it is above the content */ + pointer-events: none; /* Allow clicks to pass through the overlay */ +}
M
src/app/layout.js
→
src/app/layout.js
@@ -2,6 +2,7 @@ "use client";
import { Geist, Geist_Mono } from "next/font/google"; import { AuthProvider } from "@/context/AuthContext"; +import { useEffect, useState } from "react"; import "./globals.css"; const geistSans = Geist({@@ -14,17 +15,19 @@ variable: "--font-geist-mono",
subsets: ["latin"], }); -// export const metadata = { -// title: "Argus Dashboard", -// description: "Dashboard for Argus Logging Platform", -// }; +export default function RootLayout({ children }) { + const [isLocalhost, setIsLocalhost] = useState(false); + + useEffect(() => { + setIsLocalhost(window.location.hostname === "localhost"); + }, []); -export default function RootLayout({ children }) { return ( <html lang="en"> <body className={`${geistSans.variable} ${geistMono.variable} text-gray-800 min-h-screen bg-white antialiased`} > + {isLocalhost && <div className="overlay"></div>} <AuthProvider>{children}</AuthProvider> </body> </html>
M
src/context/AuthContext.js
→
src/context/AuthContext.js
@@ -13,18 +13,25 @@
// Function to fetch user data using the token const fetchUserData = async (token) => { try { - const response = await fetch("http://localhost:8080/auth/me", { - headers: { - Authorization: `Bearer ${token}`, + const response = await fetch( + "http://localhost:8080/twirp/auth.AuthService/ValidateToken", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + token: token, + }), }, - }); + ); if (!response.ok) { throw new Error("Failed to fetch user data" + response.statusText); } const userData = await response.json(); - setUser(userData); + setUser(userData.user); return userData; } catch (error) { console.error("Error fetching user data:", error);