Save gitHub token in DB and unauthenticate on expiry (#58)

This commit is contained in:
2024-02-01 11:37:57 +05:30
committed by Ashwin Phatak
parent 0dd6c7702a
commit 3a7f16467e
13 changed files with 155 additions and 76 deletions
+12 -4
View File
@@ -1,8 +1,8 @@
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getDomains, getProjectsInOrganization } from './queries';
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGithubResponse, UpdateEnvironmentVariableResponse, UpdateEnvironmentVariableInput, RemoveEnvironmentVariableResponse, UpdateProjectMemberInput, RemoveProjectMemberResponse, UpdateProjectMemberResponse } from './types';
import { removeProjectMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGithub, updateEnvironmentVariable, removeEnvironmentVariable, updateProjectMember } from './mutations';
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGitHubResponse, UnauthenticateGitHubResponse, UpdateEnvironmentVariableResponse, UpdateEnvironmentVariableInput, RemoveEnvironmentVariableResponse, UpdateProjectMemberInput, RemoveProjectMemberResponse, UpdateProjectMemberResponse } from './types';
import { removeProjectMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGitHub, unauthenticateGitHub, updateEnvironmentVariable, removeEnvironmentVariable, updateProjectMember } from './mutations';
export interface GraphQLConfig {
gqlEndpoint: string;
@@ -263,9 +263,9 @@ export class GQLClient {
return data;
}
async authenticateGithub (code: string): Promise<AuthenticateGithubResponse> {
async authenticateGitHub (code: string): Promise<AuthenticateGitHubResponse> {
const { data } = await this.client.mutate({
mutation: authenticateGithub,
mutation: authenticateGitHub,
variables: {
code
}
@@ -273,4 +273,12 @@ export class GQLClient {
return data;
}
async unauthenticateGithub (): Promise<UnauthenticateGitHubResponse> {
const { data } = await this.client.mutate({
mutation: unauthenticateGitHub
});
return data;
}
}
+7 -2
View File
@@ -70,9 +70,14 @@ mutation ($projectId: String!, $domainDetails: AddDomainInput!) {
}
`;
export const authenticateGithub = gql`
export const authenticateGitHub = gql`
mutation ($code: String!) {
authenticateGithub(code: $code) {
authenticateGitHub(code: $code) {
token
}
}`;
export const unauthenticateGitHub = gql`
mutation {
unauthenticateGitHub
}`;
+1
View File
@@ -8,6 +8,7 @@ query {
email
createdAt
updatedAt
gitHubToken
}
}
`;
+7 -2
View File
@@ -53,6 +53,7 @@ export type User = {
email: string
createdAt: string
updatedAt: string
gitHubToken: string | null
}
export type Deployment = {
@@ -244,8 +245,12 @@ export type AddDomainResponse = {
addDomain: true
}
export type AuthenticateGithubResponse = {
authenticateGithub: {
export type AuthenticateGitHubResponse = {
authenticateGitHub: {
token: string
}
}
export type UnauthenticateGitHubResponse = {
unauthenticateGitHub: boolean
}