Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
env: {
VITE_BASE_API_URL: process.env.VITE_BASE_API_URL
}
};

module.exports = nextConfig;
3 changes: 2 additions & 1 deletion util/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getEnv } from "./env";
import { handleError } from "./helpers";
import {
AcceptAdmissionRSVPRequest,
Expand All @@ -11,7 +12,7 @@ import {
EventType
} from "./types";

const APIv2 = "https://adonix.hackillinois.org";
const APIv2 = getEnv("VITE_BASE_API_URL");

export const isAuthenticated = async (): Promise<boolean> => {
return (await getAuthToken()) !== null;
Expand Down
18 changes: 18 additions & 0 deletions util/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Type-safe environment variable access.
* Add new env variables to the `envVars` object below and to `next.config.js`'s `env` option.
*/

const envVars = {
VITE_BASE_API_URL: process.env.VITE_BASE_API_URL
} as const;

type EnvKey = keyof typeof envVars;

export function getEnv(key: EnvKey): string {
const value = envVars[key];
if (!value) {
throw new Error(`Missing required environment variable: ${key}`);
}
return value;
}
3 changes: 3 additions & 0 deletions wrangler.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"assets": {
"directory": ".open-next/assets",
"binding": "ASSETS"
},
"vars": {
"VITE_BASE_API_URL": "https://adonix.hackillinois.org"
}
}