Skip to content

Commit

Permalink
WIP: check auth status
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnugget committed May 15, 2023
1 parent f6dfaf3 commit 1282e91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions client/cody-shared/src/sourcegraph-api/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SEARCH_EMBEDDINGS_QUERY,
LOG_EVENT_MUTATION,
REPOSITORY_EMBEDDING_EXISTS_QUERY,
CURRENT_USER_ID_VERIFICATION_STATUS_QUERY,
AUTH_STATUS_QUERY,
} from './queries'

interface APIResponse<T> {
Expand Down Expand Up @@ -90,13 +90,17 @@ export class SourcegraphGraphQLAPIClient {
)
}

public async getCurrentUserIDAndVerificationStatus(): Promise<{ id: string; hasVerifiedEmail: boolean } | Error> {
public async getAuthStatus(): Promise<
{ id: string; hasVerifiedEmail: boolean; requiresVerifiedEmail: boolean } | Error
> {
return this.fetchSourcegraphAPI<APIResponse<CurrentUserIdVerificationStatusResponse>>(
CURRENT_USER_ID_VERIFICATION_STATUS_QUERY,
AUTH_STATUS_QUERY,
{}
).then(response =>
extractDataOrError(response, data =>
data.currentUser ? data.currentUser : new Error('current user not found')
data.currentUser
? { ...data.currentUser, requiresVerifiedEmail: data.site.requiresVerifiedEmailForCody }
: new Error('current user not found')
)
)
}
Expand Down
6 changes: 5 additions & 1 deletion client/cody-shared/src/sourcegraph-api/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ query CurrentUser {
}
}`

export const CURRENT_USER_ID_VERIFICATION_STATUS_QUERY = `
// TODO: We can only query these fields on dotcom ... instrospection query?
export const AUTH_STATUS_QUERY = `
query CurrentUser {
site {
requiresVerifiedEmailForCody
}
currentUser {
id
hasVerifiedEmail
Expand Down

0 comments on commit 1282e91

Please sign in to comment.