Skip to content

Commit 3793768

Browse files
authored
fix: update AuthGate to use environment variable for Coder URL (#51)
* fix: update AuthGate to use environment variable for Coder URL - Modified AuthGate component to retrieve Coder URL from environment variable instead of hardcoding. - Added new CODER_URL definition in env.d.ts for better configuration management. * refactor: enhance Vite configuration to load environment variables - Updated vite.config.mts to load environment variables based on the current mode, allowing for better configuration management. - Made CODER_URL available through import.meta.env for improved flexibility in accessing environment-specific settings. * fix: update AuthGate to use corrected environment variable for Coder URL - Changed the environment variable reference in AuthGate from VITE_CODER_URL to CODER_URL for consistency with the updated configuration management.
1 parent 491e84d commit 3793768

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/frontend/src/AuthGate.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export default function AuthGate({ children }: { children: React.ReactNode }) {
2121
if (isAuthenticated === true && !coderAuthDone) {
2222
const iframe = document.createElement("iframe");
2323
iframe.style.display = "none";
24-
iframe.src = "https://coder.pad.ws/api/v2/users/oidc/callback";
24+
const coderUrl = import.meta.env.CODER_URL;
25+
iframe.src = `${coderUrl}/api/v2/users/oidc/callback`;
26+
console.debug(`[pad.ws] (Silently) Priming Coder OIDC session for ${coderUrl}`);
2527

2628
// Remove iframe as soon as it loads, or after 2s fallback
2729
const cleanup = () => {

src/frontend/src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
interface ImportMetaEnv {
44
readonly VITE_PUBLIC_POSTHOG_KEY: string
55
readonly VITE_PUBLIC_POSTHOG_HOST: string
6+
readonly CODER_URL: string
67
}
78

89
interface ImportMeta {

src/frontend/vite.config.mts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
import { defineConfig } from "vite";
1+
import { defineConfig, loadEnv } from "vite";
22

33
// https://vitejs.dev/config/
4-
export default defineConfig({
5-
server: {
6-
port: 3003,
7-
open: false, // open the browser where app is started
8-
proxy: {
9-
// Proxy PostHog requests to avoid CORS issues
10-
'/posthog': {
11-
target: 'https://eu.i.posthog.com',
12-
changeOrigin: true,
13-
rewrite: (path) => path.replace(/^\/posthog/, ''),
4+
export default defineConfig(({ mode }) => {
5+
// Load env file based on `mode` in the current working directory.
6+
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
7+
const env = loadEnv(mode, process.cwd(), '');
8+
9+
return {
10+
server: {
11+
port: 3003,
12+
open: false, // open the browser where app is started
13+
proxy: {
14+
// Proxy PostHog requests to avoid CORS issues
15+
'/posthog': {
16+
target: 'https://eu.i.posthog.com',
17+
changeOrigin: true,
18+
rewrite: (path) => path.replace(/^\/posthog/, ''),
19+
},
1420
},
1521
},
16-
},
17-
publicDir: "public",
18-
optimizeDeps: {
19-
esbuildOptions: {
20-
// Bumping to 2022 due to "Arbitrary module namespace identifier names" not being
21-
// supported in Vite's default browser target https://github.com/vitejs/vite/issues/13556
22-
target: "es2022",
23-
treeShaking: true,
22+
define: {
23+
// Make non-prefixed CODER_URL available to import.meta.env
24+
'import.meta.env.CODER_URL': JSON.stringify(env.CODER_URL),
2425
},
25-
},
26+
publicDir: "public",
27+
optimizeDeps: {
28+
esbuildOptions: {
29+
// Bumping to 2022 due to "Arbitrary module namespace identifier names" not being
30+
// supported in Vite's default browser target https://github.com/vitejs/vite/issues/13556
31+
target: "es2022",
32+
treeShaking: true,
33+
},
34+
},
35+
};
2636
});

0 commit comments

Comments
 (0)