diff --git a/backend/.env.example b/backend/.env.example index 0e68a75..b42994f 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,2 +1,5 @@ MONGO= ORIGIN= +PORT= + +AUTH_KEY= \ No newline at end of file diff --git a/backend/src/Controllers/team.ts b/backend/src/Controllers/team.ts index 5963b91..702d987 100644 --- a/backend/src/Controllers/team.ts +++ b/backend/src/Controllers/team.ts @@ -1,5 +1,11 @@ import Team from "../Model/team"; import{ Request, Response } from "express"; +import dotenv from "dotenv"; + + +dotenv.config(); + +const AUTH_KEY = process.env.AUTH_KEY || ""; const expectTeamCount = 50; @@ -98,3 +104,32 @@ export const count = (req: Request, res: Response): void => { }; + +// get teams , autherization key is required + +export const getTeams = async (req: Request, res: Response) => { + const authKey = req.headers.authorization; + if (authKey !== AUTH_KEY) { + res.status(401).json({ + success: false, + message: "Unauthorized", + }); + return; + } + try { + const teams = await Team.find({}); + res.status(200).json({ + success: true, + message: "Teams fetched successfully", + data: teams, + }); + } catch (err) { + res.status(500).json({ + success: false, + message: "Error fetching teams", + data: err, + }); + } +}; + + diff --git a/backend/src/Routes/team.ts b/backend/src/Routes/team.ts index fab49a7..d761cfc 100644 --- a/backend/src/Routes/team.ts +++ b/backend/src/Routes/team.ts @@ -1,9 +1,10 @@ import express from "express"; -import { register,count } from "../Controllers/team"; +import { register,count, getTeams } from "../Controllers/team"; const router = express.Router(); router.post("/register", register); router.get("/count", count); +router.get("/getTeams", getTeams); export default router; \ No newline at end of file diff --git a/backend/src/index.ts b/backend/src/index.ts index bd7f1ed..a412a5d 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -10,6 +10,8 @@ const URL = process.env.MONGO || "mongodb://localhost:27017/"; const ORIGIN = process.env.ORIGIN || "http://localhost:3000"; const PORT = process.env.PORT || 4000; +const AUTH_KEY = process.env.AUTH_KEY || "123456"; + const app: Express = express(); app.use(express.json()); app.use(cors( diff --git a/frontend/package.json b/frontend/package.json index c01e667..26dfa9c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ "@types/react": "^18.2.43", "@types/react-dom": "^18.2.17", "@types/react-vertical-timeline-component": "^3.3.6", + "axios": "^1.6.7", "bootstrap": "^5.3.2", "framer-motion": "^10.16.16", "react": "^18.2.0", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 6a701a1..02228af 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -32,6 +32,9 @@ dependencies: '@types/react-vertical-timeline-component': specifier: ^3.3.6 version: 3.3.6 + axios: + specifier: ^1.6.7 + version: 1.6.7 bootstrap: specifier: ^5.3.2 version: 5.3.2(@popperjs/core@2.11.8) @@ -3358,6 +3361,16 @@ packages: engines: {node: '>=4'} dev: false + /axios@1.6.7: + resolution: {integrity: sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==} + dependencies: + follow-redirects: 1.15.5 + form-data: 4.0.0 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + dev: false + /axobject-query@3.2.1: resolution: {integrity: sha512-jsyHu61e6N4Vbz/v18DHwWYKK0bSWLqn47eeDSKPB7m8tqMHF9YJ+mhIk2lVteyZrY8tnSj/jHOv4YiTCuCJgg==} dependencies: @@ -5355,6 +5368,16 @@ packages: optional: true dev: false + /follow-redirects@1.15.5: + resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dev: false + /for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} dependencies: @@ -5402,6 +5425,15 @@ packages: mime-types: 2.1.35 dev: false + /form-data@4.0.0: + resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} + engines: {node: '>= 6'} + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + mime-types: 2.1.35 + dev: false + /forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} engines: {node: '>= 0.6'} @@ -8543,6 +8575,10 @@ packages: ipaddr.js: 1.9.1 dev: false + /proxy-from-env@1.1.0: + resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + dev: false + /psl@1.9.0: resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==} dev: false diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 74c981c..58fadc0 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -23,14 +23,19 @@ import Intro from "./Components/Introduction/Intro"; import ContactUS from "./Components/ContactUs/ContactUs"; +import Teams from './Components/Admin/Teams' + + const App = () => { return (
Error: {error}
} +