Skip to content

Commit

Permalink
Use env files for config (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
argaen authored May 26, 2024
1 parent 8c811b3 commit d50c11a
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_AUTH0_DOMAIN=maffin-dev.eu.auth0.com
NEXT_PUBLIC_AUTH0_CLIENT_ID=mMmnR4NbQOnim9B8QZfe9wfFuaKb8rwW
NEXT_PUBLIC_AUTH0_SCOPES=profile email
3 changes: 3 additions & 0 deletions .env.master
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_AUTH0_DOMAIN=maffin.eu.auth0.com
NEXT_PUBLIC_AUTH0_CLIENT_ID=cEXnN96kEP3ER2EDJjmjRW0u2MEFBUKK
NEXT_PUBLIC_AUTH0_SCOPES=profile email https://www.googleapis.com/auth/drive.file
3 changes: 3 additions & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_AUTH0_DOMAIN=maffin-dev.eu.auth0.com
NEXT_PUBLIC_AUTH0_CLIENT_ID=mMmnR4NbQOnim9B8QZfe9wfFuaKb8rwW
NEXT_PUBLIC_AUTH0_SCOPES=profile email
3 changes: 3 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_AUTH0_DOMAIN=maffin-dev.eu.auth0.com
NEXT_PUBLIC_AUTH0_CLIENT_ID=mMmnR4NbQOnim9B8QZfe9wfFuaKb8rwW
NEXT_PUBLIC_AUTH0_SCOPES=profile email
1 change: 1 addition & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ frontend:
build:
commands:
- rm -rf .next/
- cp .env.$USER_BRANCH .env
- NEXT_PUBLIC_ENV=$USER_BRANCH yarn maffin:build
artifacts:
baseDirectory: .next
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/components/buttons/SaveButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as helpers_env from '@/helpers/env';
import * as stateHooks from '@/hooks/state';

jest.mock('@tanstack/react-query');
jest.mock('@/lib/prices');

jest.mock('@/helpers/env', () => ({
__esModule: true,
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/hooks/useDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jest.mock('@/lib/queries', () => ({

jest.mock('@/lib/prices', () => ({
__esModule: true,
...jest.requireActual('@/lib/prices'),
insertTodayPrices: jest.fn(),
}));

Expand Down
26 changes: 0 additions & 26 deletions src/helpers/env.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,2 @@
export const IS_PAID_PLAN: boolean = process.env.NEXT_PUBLIC_ENV === 'master';
export const IS_DEMO_PLAN = !IS_PAID_PLAN;

const PAID_PLAN_CONFIG = {
auth0: {
domain: 'maffin.eu.auth0.com',
clientId: 'cEXnN96kEP3ER2EDJjmjRW0u2MEFBUKK',
scopes: 'profile email https://www.googleapis.com/auth/drive.file',
},
};

const DEMO_PLAN_CONFIG = {
auth0: {
domain: 'maffin-dev.eu.auth0.com',
clientId: 'mMmnR4NbQOnim9B8QZfe9wfFuaKb8rwW',
scopes: 'profile email',
},
};

function getConfig() {
if (IS_PAID_PLAN) {
return PAID_PLAN_CONFIG;
}

return DEMO_PLAN_CONFIG;
}

export const CONFIG = getConfig();
7 changes: 3 additions & 4 deletions src/lib/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import {
} from '@auth0/auth0-react';

import { Actions } from '@/app/actions';
import { CONFIG } from '@/helpers/env';

export default function Provider({
children,
}: React.PropsWithChildren): JSX.Element {
return (
<Auth0Provider
domain={CONFIG.auth0.domain}
clientId={CONFIG.auth0.clientId}
domain={process.env.NEXT_PUBLIC_AUTH0_DOMAIN as string}
clientId={process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID as string}
authorizationParams={{
redirect_uri: (typeof window !== 'undefined' && window.location.origin) || '',
scope: CONFIG.auth0.scopes,
scope: process.env.NEXT_PUBLIC_AUTH0_SCOPES,
connection: 'maffin-gcp',
audience: 'https://maffin',
}}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import jwt from 'jsonwebtoken';
import { JwksClient } from 'jwks-rsa';
import type { JwtHeader, JwtPayload, SigningKeyCallback } from 'jsonwebtoken';

import { CONFIG } from '@/helpers/env';

function getKey(header: JwtHeader, callback: SigningKeyCallback) {
const client = new JwksClient({
jwksUri: `https://${CONFIG.auth0.domain}/.well-known/jwks.json`,
jwksUri: `https://${process.env.NEXT_PUBLIC_AUTH0_DOMAIN}/.well-known/jwks.json`,
});

client.getSigningKey(header.kid, (_, key) => {
Expand Down

0 comments on commit d50c11a

Please sign in to comment.