From 1e795d6149c041af0bf0ce878316e481765c0a96 Mon Sep 17 00:00:00 2001 From: Calvin Secrest Date: Sun, 31 Aug 2025 22:41:52 -0400 Subject: [PATCH] Include API key and auth headers --- frontend/next.config.js | 6 +++++- frontend/user_login.js | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/next.config.js b/frontend/next.config.js index 767719f..7387d93 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + env: { + NEXT_PUBLIC_API_KEY: process.env.NEXT_PUBLIC_API_KEY, + }, +}; module.exports = nextConfig diff --git a/frontend/user_login.js b/frontend/user_login.js index 4f59ec3..31c07e0 100644 --- a/frontend/user_login.js +++ b/frontend/user_login.js @@ -2,6 +2,7 @@ import { useState, useEffect } from "react"; import axios from "axios"; const BASE_URL = process.env.NEXT_PUBLIC_BACKEND_URL || "/api"; +const API_KEY = process.env.NEXT_PUBLIC_API_KEY; export default function AuthPage() { const [form, setForm] = useState({ email: "", password: "" }); @@ -15,6 +16,10 @@ export default function AuthPage() { useEffect(() => { const token = localStorage.getItem("token"); if (token) { + axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; + if (API_KEY) { + axios.defaults.headers.common["x-api-key"] = API_KEY; + } setAdminView(true); fetchUsers(); fetchKeys(); @@ -27,8 +32,16 @@ export default function AuthPage() { const handleLogin = async () => { try { - const res = await axios.post(`${BASE_URL}/auth/login`, form); + const res = await axios.post( + `${BASE_URL}/auth/login`, + form, + API_KEY ? { headers: { "x-api-key": API_KEY } } : undefined + ); localStorage.setItem("token", res.data.token); + axios.defaults.headers.common["Authorization"] = `Bearer ${res.data.token}`; + if (API_KEY) { + axios.defaults.headers.common["x-api-key"] = API_KEY; + } setMessage("Login successful!"); setAdminView(true); fetchUsers();