Skip to content
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

Cody VSCode: Add support for verified email check message when connected to app; and improve connected status message #52075

Merged
merged 2 commits into from
May 17, 2023
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
3 changes: 2 additions & 1 deletion client/cody/src/chat/ChatViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
DOTCOM_URL,
ExtensionMessage,
WebviewMessage,
isLocalApp,
isLoggedIn,
} from './protocol'

Expand All @@ -53,7 +54,7 @@ export async function getAuthStatus(
}

const client = new SourcegraphGraphQLAPIClient(config)
if (client.isDotCom()) {
if (client.isDotCom() || isLocalApp(config.serverEndpoint)) {
const data = await client.getCurrentUserIdAndVerifiedEmail()
return {
showInvalidAccessTokenError: isError(data),
Expand Down
4 changes: 4 additions & 0 deletions client/cody/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ export interface AuthStatus {
export function isLoggedIn(authStatus: AuthStatus): boolean {
return authStatus.authenticated && (authStatus.requiresVerifiedEmail ? authStatus.hasVerifiedEmail : true)
}

export function isLocalApp(url: string): boolean {
return new URL(url).origin === LOCAL_APP_URL.origin
}
2 changes: 1 addition & 1 deletion client/cody/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const register = async (
if (token && token.length > 8) {
await secretStorage.store(CODY_ACCESS_TOKEN_SECRET, token)
const authStatus = await getAuthStatus({
serverEndpoint: DOTCOM_URL.href,
serverEndpoint,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a regression; serverEndpoint is already set above to DOTCOM_URL if we're connecting to dotcom, or it's set to LOCAL_APP_URL if we're connecting to App so we don't want to overwrite it here.

accessToken: token,
customHeaders: config.customHeaders,
})
Expand Down
6 changes: 5 additions & 1 deletion client/cody/webviews/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'

import './Settings.css'

import { isLocalApp } from '../src/chat/protocol'

interface SettingsProps {
onLogout: () => void
serverEndpoint?: string
Expand All @@ -14,7 +16,9 @@ export const Settings: React.FunctionComponent<React.PropsWithChildren<SettingsP
<div className="inner-container">
<div className="non-transcript-container">
<div className="settings">
{serverEndpoint && <p>🟢 Connected to {serverEndpoint}</p>}
{serverEndpoint && (
<p>🟢 Connected to {isLocalApp(serverEndpoint) ? 'Sourcegraph App' : serverEndpoint}</p>
)}
<VSCodeButton className="logout-button" type="button" onClick={onLogout}>
Logout
</VSCodeButton>
Expand Down
Loading