forked from SagnikBasak04/KisanSahayak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marketplace integration-1: Buying Items
- Loading branch information
Showing
17 changed files
with
653 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import express from "express"; | ||
import verifyToken from "../middlewares/auth.middleware.js"; | ||
import { createMetaData, getMetaData } from "../controllers/elevatedUser.controller.js"; | ||
import { createMetaData, getMetaData, isElevatedUser } from "../controllers/elevatedUser.controller.js"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/metadata", verifyToken, createMetaData); | ||
router.get("/get-metadata", verifyToken, getMetaData); | ||
router.get("/isElevatedUser", verifyToken, isElevatedUser); | ||
|
||
export default router; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable react-refresh/only-export-components */ | ||
import { createContext, useContext, useEffect, useState } from "react"; | ||
import useGetIsElevatedUser from "../hooks/getIsElevatedUser"; | ||
|
||
export const ElevatedUserContext = createContext(); | ||
|
||
export const useElevatedUserContext = () => { | ||
return useContext(ElevatedUserContext); | ||
} | ||
|
||
export const ElevatedUserContextProvider = ({ children }) => { | ||
const { isElevatedUser } = useGetIsElevatedUser(); | ||
const [elevatedUser, setElevatedUser] = useState(false); | ||
|
||
const getElevatedUser = async () => { | ||
const data = await isElevatedUser(); | ||
setElevatedUser(data); | ||
} | ||
|
||
useEffect(() => { | ||
getElevatedUser(); | ||
}, []); | ||
|
||
return <ElevatedUserContext.Provider value={{ elevatedUser, setElevatedUser }}> | ||
{children} | ||
</ElevatedUserContext.Provider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useState } from "react"; | ||
import toast from "react-hot-toast"; | ||
|
||
const useGetIsElevatedUser = () => { | ||
const [loading, setLoading] = useState(false); | ||
const apiUrl = import.meta.env.VITE_API_URL; | ||
|
||
const isElevatedUser = async (id) => { | ||
setLoading(true); | ||
try { | ||
const res = await fetch(`${apiUrl}/elevatedUser/isElevatedUser`, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${localStorage.getItem("KS-token")}`, | ||
} | ||
}); | ||
const data = await res.json(); | ||
|
||
if (data.error) { | ||
throw new Error(data.error); | ||
} | ||
|
||
return data.elevatedUser; | ||
} catch (error) { | ||
toast.error(error.message); | ||
console.log(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
} | ||
return { loading, isElevatedUser } | ||
} | ||
|
||
export default useGetIsElevatedUser; |
Oops, something went wrong.