Skip to content

Commit a48c284

Browse files
author
Ubuntu
committed
feat: add admin-only route access
1 parent d515bb5 commit a48c284

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.env.example

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export CODER_OIDC_REDIRECT_URI="$BASE_URL/api/v2/users/oidc/callback"
1515
export CODER_OIDC_LOGOUT_URI="https://oidc.logout.url"
1616
export CODER_OIDC_TOKEN_PATH="/home/ubuntu/.coder/tokens"
1717

18-
# if VITE_DISABLE_EXTERNAL_LOGIN_PAGE variable is true, CODER_DISABLE_PASSWORD_AUTH variable must be false
19-
export VITE_DISABLE_EXTERNAL_LOGIN_PAGE=true
20-
export CODER_DISABLE_PASSWORD_AUTH=false
18+
export VITE_CLIENT_URL="https://client.url"
19+
export VITE_ADMIN_KEY_HASH="hash"
20+
export CODER_DISABLE_PASSWORD_AUTH=false
21+
22+
# GPU Manager
23+
export TF_VAR_gpu_manager_endpoint="https://gpu.manager.endpoint"
24+
export APP_TYPE="development"

site/src/@types/vite-env.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ interface ViteTypeOptions {
55
}
66

77
interface ImportMetaEnv {
8-
readonly VITE_DISABLE_EXTERNAL_LOGIN_PAGE: string
8+
readonly VITE_ADMIN_KEY_HASH: string
9+
readonly VITE_CLIENT_URL: string
910
}
1011

1112
interface ImportMeta {

site/src/pages/LoginPage/LoginPage.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
55
import { type FC, useEffect } from "react";
66
import { Helmet } from "react-helmet-async";
77
import { useQuery } from "react-query";
8-
import { Navigate, useLocation, useNavigate } from "react-router-dom";
8+
import { Navigate, useLocation, useNavigate, useSearchParams } from "react-router-dom";
99
import { getApplicationName } from "utils/appearance";
1010
import { retrieveRedirect } from "utils/redirect";
1111
import { sendDeploymentEvent } from "utils/telemetry";
1212
import { LoginPageView } from "./LoginPageView";
13+
import { paramsUsedToCreateWorkspace } from "utils/workspace";
1314

1415
export const LoginPage: FC = () => {
1516
const location = useLocation();
@@ -69,12 +70,15 @@ export const LoginPage: FC = () => {
6970
/>
7071
);
7172
}
72-
}
73+
}
74+
75+
const [params] = useSearchParams();
76+
const adminKey = params.get("adminKey")
7377

74-
const disableExternalLoginPage = import.meta.env.VITE_DISABLE_EXTERNAL_LOGIN_PAGE === "true";
78+
const isAdmin = adminKey === import.meta.env.VITE_ADMIN_KEY_HASH;
7579

76-
if (!isSignedIn && !disableExternalLoginPage) {
77-
window.location.replace(`https://heaan.io`);
80+
if (!isSignedIn && !isAdmin) {
81+
window.location.replace(import.meta.env.VITE_CLIENT_URL as string);
7882
return null;
7983
}
8084

0 commit comments

Comments
 (0)