Skip to content

Commit

Permalink
feat: Refactor configuration handling by introducing config module fo…
Browse files Browse the repository at this point in the history
…r environment variables
  • Loading branch information
fedekrenn committed Dec 19, 2024
1 parent ed357cf commit f1f0f80
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components/FetchData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import TableContainer from "./TableContainer.tsx";
import LoaderContainer from "./LoaderContainer.tsx";
// Types
import type { CompletePrediction } from "@typos/teamPrediction";
// Config
import { PUBLIC_TOKEN } from '@config/config.ts'

export default function FetchData() {
const [results, setResults] = useState<CompletePrediction[]>([]);
const [loading, setLoading] = useState<Boolean>(true);

useEffect(() => {
const TOKEN = import.meta.env.PUBLIC_TOKEN;

fetch("/api/team-info.json", {
headers: {
Authorization: TOKEN,
Authorization: PUBLIC_TOKEN,
},
})
.then((response) => {
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const { SECRET_KEY, DATABASE_URL, DATABASE_TOKEN, PUBLIC_TOKEN } =
import.meta.env;
3 changes: 1 addition & 2 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import jwt from "jsonwebtoken";

const SECRET_KEY = import.meta.env.SECRET_KEY;
import { SECRET_KEY } from "@config/config";

export const createToken = (payload: any) => {
return jwt.sign(payload, SECRET_KEY);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/users.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import bcrypt from "bcryptjs";
import { createClient } from "@libsql/client";
import type { User } from "@typos/user";
import { DATABASE_URL, DATABASE_TOKEN } from "@config/config";

const client = createClient({
url: import.meta.env.DATABASE_URL ?? "",
authToken: import.meta.env.DATABASE_TOKEN ?? "",
url: DATABASE_URL ?? "",
authToken: DATABASE_TOKEN ?? "",
});

export const addUser = async (email: string, password: string) => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"@assets/*": ["./src/assets/*"],
"@layouts/*": ["./src/layouts/*"],
"@styles/*": ["./src/components/styles/*"],
"@libs/*": ["./src/lib/*"]
"@libs/*": ["./src/lib/*"],
"@config/*": ["./src/config/*"]
},
"jsx": "react-jsx",
"jsxImportSource": "react"
Expand Down

0 comments on commit f1f0f80

Please sign in to comment.