WIP: API with 401

This commit is contained in:
Pete Gerlach
2024-06-10 00:55:13 +02:00
parent f36ea7a34b
commit 743bb06c00
6 changed files with 52 additions and 42 deletions

View File

@@ -5,6 +5,7 @@ import Modal from './components/Modal';
import './App.scss';
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {faCaretDown, faCaretUp} from "@fortawesome/free-solid-svg-icons";
import {postApi} from "./api/posts.api";
const App = () => {
const [posts, setPosts] = useState([]);
@@ -76,7 +77,8 @@ const App = () => {
return (
<div className="app">
<h1>Jodel Clone</h1>
{console.log(postApi.getPostsByCoords(48, 9), process.env.REACT_APP_AUTH_USERNAME, process.env.REACT_APP_AUTH_PASSWORD)}
<h1>SWA - Jodel</h1>
<NewPostForm addPost={addPost} />
<PostList
posts={posts}

18
src/api/posts.api.js Normal file
View File

@@ -0,0 +1,18 @@
import axios from "axios"
const path = "https://api.jodel.anxietyprime.de/post";
const config = {
headers: {
auth: {
username: process.env.REACT_APP_AUTH_USERNAME,
password: process.env.REACT_APP_AUTH_PASSWORD,
}
}
}
export const postApi = {
async getPostsByCoords (lon, lat) {
return (await axios.get(`${path}/${lon}/${lat}`, this.config)).data;
}
}