Skip to content

chore: cleanup various auth things #11785

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 1 commit into from
Jan 25, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entitlements, Feature, FeatureName } from "api/typesGenerated";
import type { Entitlements, Feature, FeatureName } from "api/typesGenerated";

/**
* @param hasLicense true if Enterprise edition
Expand Down
2 changes: 1 addition & 1 deletion site/src/modules/dashboard/useFeatureVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FeatureName } from "api/typesGenerated";
import { selectFeatureVisibility } from "./entitlements";
import { useDashboard } from "./useDashboard";
import { selectFeatureVisibility } from "utils/entitlements";

export const useFeatureVisibility = (): Record<FeatureName, boolean> => {
const { entitlements } = useDashboard();
Expand Down
21 changes: 7 additions & 14 deletions site/src/pages/CliAuthPage/CliAuthPage.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { useEffect, useState, FC, PropsWithChildren } from "react";
import { type FC } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { getApiKey } from "api/api";
import { pageTitle } from "utils/page";
import { CliAuthPageView } from "./CliAuthPageView";

export const CliAuthenticationPage: FC<PropsWithChildren<unknown>> = () => {
const [apiKey, setApiKey] = useState<string | null>(null);

useEffect(() => {
getApiKey()
.then(({ key }) => {
setApiKey(key);
})
.catch((error) => {
console.error(error);
});
}, []);
export const CliAuthenticationPage: FC = () => {
const { data } = useQuery({
queryFn: () => getApiKey(),
});

return (
<>
<Helmet>
<title>{pageTitle("CLI Auth")}</title>
</Helmet>
<CliAuthPageView sessionToken={apiKey} />
<CliAuthPageView sessionToken={data?.key} />
</>
);
};
Expand Down
40 changes: 20 additions & 20 deletions site/src/pages/CliAuthPage/CliAuthPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Button from "@mui/material/Button";
import { useTheme } from "@emotion/react";
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC } from "react";
import { Link as RouterLink } from "react-router-dom";
import { CodeExample } from "components/CodeExample/CodeExample";
Expand All @@ -8,12 +8,10 @@ import { Welcome } from "components/Welcome/Welcome";
import { FullScreenLoader } from "components/Loader/FullScreenLoader";

export interface CliAuthPageViewProps {
sessionToken: string | null;
sessionToken?: string;
}

export const CliAuthPageView: FC<CliAuthPageViewProps> = ({ sessionToken }) => {
const theme = useTheme();

if (!sessionToken) {
return <FullScreenLoader />;
}
Expand All @@ -22,15 +20,7 @@ export const CliAuthPageView: FC<CliAuthPageViewProps> = ({ sessionToken }) => {
<SignInLayout>
<Welcome>Session token</Welcome>

<p
css={{
fontSize: 16,
color: theme.palette.text.secondary,
marginBottom: 32,
textAlign: "center",
lineHeight: "160%",
}}
>
<p css={styles.instructions}>
Copy the session token below and{" "}
<strong css={{ whiteSpace: "nowrap" }}>
paste it in your terminal
Expand All @@ -40,17 +30,27 @@ export const CliAuthPageView: FC<CliAuthPageViewProps> = ({ sessionToken }) => {

<CodeExample code={sessionToken} secret />

<div
css={{
display: "flex",
justifyContent: "flex-end",
paddingTop: 8,
}}
>
<div css={styles.backButton}>
<Button component={RouterLink} size="large" to="/workspaces" fullWidth>
Go to workspaces
</Button>
</div>
</SignInLayout>
);
};

const styles = {
instructions: (theme) => ({
fontSize: 16,
color: theme.palette.text.secondary,
marginBottom: 32,
textAlign: "center",
lineHeight: "160%",
}),

backButton: {
display: "flex",
justifyContent: "flex-end",
paddingTop: 8,
},
} satisfies Record<string, Interpolation<Theme>>;