Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved the issue for Exposed authInfo and made it in .env file #159

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
Expand Down
70 changes: 37 additions & 33 deletions src/components/Quotes/QuotesSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@ import quotes from "/src/database/quotes.json";
import "./QuoteSection.css";

const QuoteSection = () => {
const [quote, setQuote] = useState("");
const [quote, setQuote] = useState("");
const AuthInfo = process.env.QUOTES_API_KEY;

useEffect(() => {
fetchDailyQuote();
}, []);
useEffect(() => {
fetchDailyQuote();
}, []);

const fetchDailyQuote = async () => {
try {
const response = await fetch("https://api.yourquoteapi.com/quotes?author=Chanakya", {
headers: {
"Authorization": `4fe303f4bamshb97ef5b1dd575e0p1ccc51jsnd9644d3c587b`
const fetchDailyQuote = async () => {
try {
const response = await fetch(
"https://api.yourquoteapi.com/quotes?author=Chanakya",
{
headers: {
Authorization: AuthInfo,
},
}
);
const data = await response.json();
if (data && data.length > 0) {
setQuote(data[0].quote);
} else {
setFallbackQuote();
}
} catch (error) {
console.error("Error fetching the quote:", error);
setFallbackQuote();
}
});
const data = await response.json();
if (data && data.length > 0) {
setQuote(data[0].quote);
} else {
setFallbackQuote();
}
} catch (error) {
console.error("Error fetching the quote:", error);
setFallbackQuote();
}
};
};

const setFallbackQuote = () => {
const randomIndex = Math.floor(Math.random() * quotes.length);
setQuote(quotes[randomIndex].quote);
};
const setFallbackQuote = () => {
const randomIndex = Math.floor(Math.random() * quotes.length);
setQuote(quotes[randomIndex].quote);
};

return (
<div className="d-flex align-items-center justify-content-center">
<div className="d-flex flex-column flex-md-row align-items-center">
<div className="text-center text-md-start">
<p className="quote-text">"{quote}"</p>
return (
<div className="d-flex align-items-center justify-content-center">
<div className="d-flex flex-column flex-md-row align-items-center">
<div className="text-center text-md-start">
<p className="quote-text">"{quote}"</p>
</div>
</div>
</div>
</div>
</div>
);
);
};

export default QuoteSection;
10 changes: 5 additions & 5 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "bootstrap/dist/css/bootstrap.min.css";
import 'bootstrap/dist/js/bootstrap.bundle.min';
import "./index.css"
import "bootstrap/dist/js/bootstrap.bundle.min";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>,
<React.StrictMode>
<App />
</React.StrictMode>
);