added authentication

This commit was merged in pull request #7.
This commit is contained in:
2023-10-21 03:06:58 -07:00
parent ed2ebe41e6
commit c48c959749
7 changed files with 327 additions and 55 deletions
+61
View File
@@ -0,0 +1,61 @@
import Axios from "axios";
class Fetcher {
constructor(url) {
// this.url = url;
console.log("first request!!!");
}
// Endpoints Here
// GET /api/
// POST /api/
login(values) {
return this.postAuxEnd("/auth/login", values);
}
//---------------------------------------- -----
// Unified call below
//---------------------------------------- -----
async getAuxEnd(uri, reqData) {
const endPoint =
(process.env.AUX_ENDPOINT || "http://localhost:50016/api") + uri;
console.log("Checking endpoint get request", endPoint);
try {
const response = await Axios.get(endPoint);
console.log(response.data); // Log the response data if needed.
return response.data;
} catch (error) {
this.handleAxiosError(error);
}
}
async postAuxEnd(uri, reqData) {
const endPoint =
(process.env.AUX_ENDPOINT || "http://localhost:50016/api") + uri;
console.log("Checking endpoint post request", endPoint);
try {
const response = await Axios.post(endPoint, reqData);
console.log(response.data); // Log the response data if needed.
return response.data;
} catch (error) {
this.handleAxiosError(error);
}
}
handleAxiosError(error) {
if (error.response) {
// Response status is an error code.
console.log(error.response.status);
} else if (error.request) {
// Response not received though the request was sent.
console.log(error.request);
} else {
// An error occurred when setting up the request.
console.log(error.message);
}
}
}
export default Fetcher;