feat: Add JWT authentication to backend, configure frontend API client, fix streak layout
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { fetchWithAuth } from "@/lib/apiClient";
|
||||
import { useState, useEffect, useRef } from "react"
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -55,7 +56,7 @@ export default function AdminTestsPage() {
|
||||
|
||||
const fetchTests = async () => {
|
||||
try {
|
||||
const res = await fetch("/api/admin/tests")
|
||||
const res = await fetchWithAuth("/api/admin/tests")
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setTests(data)
|
||||
@@ -74,7 +75,7 @@ export default function AdminTestsPage() {
|
||||
|
||||
const handleToggle = async (testId: string) => {
|
||||
try {
|
||||
const res = await fetch(`/api/admin/tests/${testId}/toggle`, {
|
||||
const res = await fetchWithAuth(`/api/admin/tests/${testId}/toggle`, {
|
||||
method: "PUT"
|
||||
})
|
||||
if (res.ok) {
|
||||
@@ -88,7 +89,7 @@ export default function AdminTestsPage() {
|
||||
const handleDelete = async (testId: string) => {
|
||||
if (!confirm("Are you sure you want to delete this test and all its questions? This action cannot be undone.")) return
|
||||
try {
|
||||
const res = await fetch(`/api/admin/tests/${testId}`, {
|
||||
const res = await fetchWithAuth(`/api/admin/tests/${testId}`, {
|
||||
method: "DELETE"
|
||||
})
|
||||
if (res.ok) {
|
||||
@@ -191,7 +192,7 @@ export default function AdminTestsPage() {
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/admin/tests/create_manual", {
|
||||
const res = await fetchWithAuth("/api/admin/tests/create_manual", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload)
|
||||
|
||||
Reference in New Issue
Block a user