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 } from "react"
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -25,7 +26,7 @@ export default function CouponsAdmin() {
|
||||
|
||||
const fetchCoupons = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/admin/coupons')
|
||||
const res = await fetchWithAuth('/api/admin/coupons')
|
||||
const data = await res.json()
|
||||
setCoupons(data)
|
||||
} catch (e) {
|
||||
@@ -39,7 +40,7 @@ export default function CouponsAdmin() {
|
||||
if (!newCoupon.code) return
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await fetch('/api/admin/coupons', {
|
||||
await fetchWithAuth('/api/admin/coupons', {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(newCoupon)
|
||||
@@ -56,7 +57,7 @@ export default function CouponsAdmin() {
|
||||
const handleDelete = async (id: string) => {
|
||||
if (!confirm("Delete this coupon?")) return
|
||||
try {
|
||||
await fetch(`/api/admin/coupons/${id}`, { method: "DELETE" })
|
||||
await fetchWithAuth(`/api/admin/coupons/${id}`, { method: "DELETE" })
|
||||
await fetchCoupons()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
||||
Reference in New Issue
Block a user