Skip to content

feat: add admin-only route access #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
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
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export CODER_OIDC_REDIRECT_URI="$BASE_URL/api/v2/users/oidc/callback"
export CODER_OIDC_LOGOUT_URI="https://oidc.logout.url"
export CODER_OIDC_TOKEN_PATH="/home/ubuntu/.coder/tokens"

# if VITE_DISABLE_EXTERNAL_LOGIN_PAGE variable is true, CODER_DISABLE_PASSWORD_AUTH variable must be false
export VITE_DISABLE_EXTERNAL_LOGIN_PAGE=true
export CODER_DISABLE_PASSWORD_AUTH=false
export VITE_CLIENT_URL="https://client.url"
export VITE_ADMIN_KEY_HASH="hash"
export CODER_DISABLE_PASSWORD_AUTH=false

# GPU Manager
export TF_VAR_gpu_manager_endpoint="https://gpu.manager.endpoint"
export APP_TYPE="development"
3 changes: 2 additions & 1 deletion site/src/@types/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ interface ViteTypeOptions {
}

interface ImportMetaEnv {
readonly VITE_DISABLE_EXTERNAL_LOGIN_PAGE: string
readonly VITE_ADMIN_KEY_HASH: string
readonly VITE_CLIENT_URL: string
}

interface ImportMeta {
Expand Down
14 changes: 9 additions & 5 deletions site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import { type FC, useEffect } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { Navigate, useLocation, useNavigate } from "react-router-dom";
import { Navigate, useLocation, useNavigate, useSearchParams } from "react-router-dom";
import { getApplicationName } from "utils/appearance";
import { retrieveRedirect } from "utils/redirect";
import { sendDeploymentEvent } from "utils/telemetry";
import { LoginPageView } from "./LoginPageView";
import { paramsUsedToCreateWorkspace } from "utils/workspace";

export const LoginPage: FC = () => {
const location = useLocation();
Expand Down Expand Up @@ -69,12 +70,15 @@ export const LoginPage: FC = () => {
/>
);
}
}
}

const [params] = useSearchParams();
const adminKey = params.get("adminKey")

const disableExternalLoginPage = import.meta.env.VITE_DISABLE_EXTERNAL_LOGIN_PAGE === "true";
const isAdmin = adminKey === import.meta.env.VITE_ADMIN_KEY_HASH;

if (!isSignedIn && !disableExternalLoginPage) {
window.location.replace(`https://heaan.io`);
if (!isSignedIn && !isAdmin) {
window.location.replace(import.meta.env.VITE_CLIENT_URL as string);
return null;
}

Expand Down