Skip to content

Commit

Permalink
chore: add config file for fetching env variables (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed Sep 21, 2023
1 parent c5da6d5 commit 4a43df4
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 69 deletions.
Binary file modified .env.local.sample
Binary file not shown.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files
.env*
# local env files
.env.local

# vercel
.vercel
Expand Down
49 changes: 2 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "citizen-directory",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -18,7 +18,6 @@
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"next-connect": "^1.0.0",
"papaparse": "^5.4.1",
"passport": "^0.6.0",
"passport-github2": "^0.1.12",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileDetailsGitHub.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContractRead } from "wagmi"
import LoadingIndicator from "./LoadingIndicator"
import GitHub from "../../abis/GitHub.json"
import { useIsMounted } from "../../hooks/useIsMounted"
import { useIsMounted } from "@/hooks/useIsMounted"
import Link from "next/link"

export default function ProfileDetailsGitHub({ citizen }: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/VeNationLockDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContractRead } from "wagmi"
import LoadingIndicator from "./LoadingIndicator"
import VotingEscrow from "../../abis/VotingEscrow.json"
import { useIsMounted } from "../../hooks/useIsMounted"
import { useIsMounted } from "@/hooks/useIsMounted"
import { formatEther } from 'viem'

export default function VeNationLockDetails({ address }: any) {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = createConfig({
const poppins = Poppins({ subsets: ['latin'], weight: '400' })

export default function App({ Component, pageProps }: AppProps) {
console.info('App')
return (
<WagmiConfig config={config}>
<main className={poppins.className}>
Expand Down
1 change: 1 addition & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
console.info('Document')
return (
<Html lang="en">
<Head />
Expand Down
14 changes: 7 additions & 7 deletions src/pages/api/[passportId]/auth/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nc, { createEdgeRouter } from "next-connect"
// import nc, { createEdgeRouter } from "next-connect"
import { NextFetchEvent, NextRequest } from "next/server"
const passport = require('passport')
const GitHubStrategy = require('passport-github2').Strategy
Expand All @@ -9,12 +9,12 @@ console.info('callbackBaseUrl:', callbackBaseUrl)
const callbackUrl = `${callbackBaseUrl}/api/233/auth/github-callback` // TODO: get [passportId]
console.info('callbackUrl:', callbackUrl)

const router = createEdgeRouter<NextRequest, NextFetchEvent>()
router.use(async (request, event, next) => {
// logging request example
console.log(`${request.method} ${request.url}`);
return next();
});
// const router = createEdgeRouter<NextRequest, NextFetchEvent>()
// router.use(async (request, event, next) => {
// // logging request example
// console.log(`${request.method} ${request.url}`);
// return next();
// });

// Configure strategy
passport.use(new GitHubStrategy(
Expand Down
19 changes: 10 additions & 9 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Papa from 'papaparse'
import Menu from '@/components/Menu'
import Link from 'next/link'
import LoadingIndicator from '@/components/LoadingIndicator'
import { config } from '@/utils/Config'

export default function Home({ total_citizens_count, total_expired_passports, active_citizens_count, citizens }: any) {
console.log('Home')
Expand Down Expand Up @@ -128,12 +129,12 @@ export async function getStaticProps() {
skipEmptyLines: true,
dynamicTyping: true,
complete: (result: any) => {
console.info('result:', result)
// console.info('result:', result)
result.data.forEach((row: any, i: number) => {
console.info(`row ${i}`, row)
// console.info(`row ${i}`, row)
active_citizens_count[i] = Number(row.active_citizens_count)
})
console.info('active_citizen_count:', active_citizens_count)
// console.info('active_citizen_count:', active_citizens_count)
}
})

Expand All @@ -150,23 +151,23 @@ export async function getStaticProps() {
skipEmptyLines: true,
dynamicTyping: true,
complete: (result: any) => {
console.info('result:', result)
// console.info('result:', result)
result.data.forEach((row: any, i: number) => {
console.info(`row ${i}`, row)
// console.info(`row ${i}`, row)
total_citizens_count[i] = Number(row.total_citizens)
total_expired_passports[i] = Number(row.total_expired_passports)
})
console.info('total_citizens_count:', total_citizens_count)
console.info('total_expired_passports:', total_expired_passports)
// console.info('total_citizens_count:', total_citizens_count)
// console.info('total_expired_passports:', total_expired_passports)
}
})

// Fetch citizen data from datasets repo
let citizens = null
const citizenDataFileUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/citizens/output/citizens.json'
console.info('Fetching citizen data:', citizenDataFileUrl)
// console.info('Fetching citizen data:', citizenDataFileUrl)
const response = await fetch(citizenDataFileUrl)
console.log('response.status:', response.status)
// console.log('response.status:', response.status)
citizens = await response.json()

return {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getEnvironmentVariable = (environmentVariable : string): string => {
console.log('getEnvironmentVariable', environmentVariable)
const variable = process.env[environmentVariable]
if (!variable) {
throw new Error(`Missing variable: "${environmentVariable}"`)
} else {
return variable
}
}

export const config = {
gitHubCallbackBaseUrl: getEnvironmentVariable('GITHUB_CALLBACK_BASE_URL'),
gitHubClientId: getEnvironmentVariable('GITHUB_CLIENT_ID'),
gitHubClientSecret: getEnvironmentVariable('GITHUB_CLIENT_ID')
}
console.log('config:', config)

0 comments on commit 4a43df4

Please sign in to comment.