Skip to content

Commit f1f45df

Browse files
maveroxbenjagm
andauthored
Enhancement: use env vars instead of hardcoded credentials (#527)
* Feat: use env vars instead of hardcoded credentials changed hardcoded instances created and implemented env files and variables. * fix: minor issue closing bracket after merge * Solve merge conflicts --------- Co-authored-by: Benjamin Granados <[email protected]> Co-authored-by: Benjamin Granados <[email protected]>
1 parent bb88390 commit f1f45df

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NEXT_PUBLIC_ALGOLIA_API_KEY=
2+
NEXT_PUBLIC_ALGOLIA_APP_ID=

components/Layout.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Props = {
1717
metaTitle?: string;
1818
whiteBg?: boolean;
1919
};
20+
// apiKey and appId are set in the .env.local file
21+
const algoliaAppId: string = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID as string;
22+
const algoliaApiKey: string = process.env.NEXT_PUBLIC_ALGOLIA_API_KEY as string;
2023

2124
// const responsiveClasses = 'w-screen'
2225

@@ -119,8 +122,8 @@ export default function Layout({
119122
export const Search = () => {
120123
return (
121124
<DocSearch
122-
appId='6ZT4KX2OUI'
123-
apiKey='69f76fba13585144f6686622e9c8f2a8'
125+
appId={algoliaAppId}
126+
apiKey={algoliaApiKey}
124127
indexName='json-schema'
125128
/>
126129
);

pages/index.page.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import axios from 'axios';
1616
import ical from 'node-ical';
1717
import moment from 'moment-timezone';
1818
import { useTheme } from 'next-themes';
19+
20+
// apiKey and appId are set in the .env.local file
21+
const algoliaAppId: string = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID as string;
22+
const algoliaApiKey: string = process.env.NEXT_PUBLIC_ALGOLIA_API_KEY as string;
23+
1924
/* eslint-enable */
2025
export const getStaticProps: GetStaticProps = async () => {
2126
const files = fs.readdirSync(PATH);
@@ -177,8 +182,8 @@ export function AlgoliaSearch() {
177182
<div className='flex herobtn items-center justify-center font-semibold w-[194px] h-[40px] rounded border-2 border-white dark:border-none hover:bg-blue-700 transition-all duration-300 ease-in-out text-white bg-primary mx-auto dark:shadow-2xl cursor-pointer'>
178183
<div className='flex flex-row justify-center items-center mr-4'>
179184
<DocSearch
180-
appId='6ZT4KX2OUI'
181-
apiKey='69f76fba13585144f6686622e9c8f2a8'
185+
appId={algoliaAppId}
186+
apiKey={algoliaApiKey}
182187
indexName='json-schema'
183188
/>
184189
Search

0 commit comments

Comments
 (0)