Skip to content

Commit 3352bf8

Browse files
committed
updated to use IdentityProvider
1 parent 479b579 commit 3352bf8

File tree

16 files changed

+113
-78
lines changed

16 files changed

+113
-78
lines changed

packages/altair-api-utils/src/client.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import {
1818
QueryItemRevision,
1919
AiChatSession,
2020
AiChatMessage,
21+
IdentityProvider,
2122
} from '@altairgraphql/db';
22-
import { AltairConfig } from 'altair-graphql-core/build/config';
23+
import { AltairConfig, getAltairConfig } from 'altair-graphql-core/build/config';
2324
import { IPlan, IPlanInfo, IUserProfile, IUserStats } from './user';
2425
import { ICreateTeamDto, ICreateTeamMembershipDto, IUpdateTeamDto } from './team';
2526
import { firstValueFrom, from, Observable, Subject } from 'rxjs';
2627
import { map, switchMap, take } from 'rxjs/operators';
2728
import { ReturnedWorkspace } from './workspace';
2829
import { ConfigEnvironment } from 'altair-graphql-core/build/config/environment';
2930
import { UrlConfig } from 'altair-graphql-core/build/config/urls';
30-
import { getAltairConfig } from 'altair-graphql-core/build/config';
3131
import { IRateMessageDto, ISendMessageDto } from './ai';
3232
import { IAvailableCredits } from 'altair-graphql-core/build/types/state/account.interfaces';
3333
export type FullQueryCollection = QueryCollection & {
@@ -126,7 +126,10 @@ export class APIClient {
126126
return String.fromCharCode(...array);
127127
}
128128

129-
private getPopupUrl(nonce: string, provider: 'google' | 'github' = 'google') {
129+
private getPopupUrl(
130+
nonce: string,
131+
provider: IdentityProvider = IdentityProvider.GOOGLE
132+
) {
130133
const url = new URL(this.urlConfig.loginClient);
131134
url.searchParams.append('nonce', nonce);
132135
url.searchParams.append('sc', location.origin);
@@ -155,13 +158,18 @@ export class APIClient {
155158
return user;
156159
}
157160

158-
async signinWithPopup(provider: 'google' | 'github' = 'google') {
159-
const token = await timeout(this.signinWithPopupGetToken(provider), SignInTimeout);
161+
async signinWithPopup(provider: IdentityProvider = IdentityProvider.GOOGLE) {
162+
const token = await timeout(
163+
this.signinWithPopupGetToken(provider),
164+
SignInTimeout
165+
);
160166

161167
return this.signInWithCustomToken(token);
162168
}
163169

164-
private async signinWithPopupGetToken(provider: 'google' | 'github' = 'google') {
170+
private async signinWithPopupGetToken(
171+
provider: IdentityProvider = IdentityProvider.GOOGLE
172+
) {
165173
const nonce = this.nonce();
166174
const popup = window.open(this.getPopupUrl(nonce, provider), '_blank');
167175
if (!popup) {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export const OAUTH_POPUP_CALLBACK_MESSAGE_TYPE =
2-
'altairgql:oauth:callback:response';
1+
export const OAUTH_POPUP_CALLBACK_MESSAGE_TYPE = 'altairgql:oauth:callback:response';
32

43
export const ALTAIR_API_USER_TOKEN_STORAGE_KEY = 'ALTAIR-API-USER-TOKEN';

packages/altair-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@nestjs/schematics": "^10.1.2",
5252
"@nestjs/testing": "^10.3.10",
5353
"@types/bcrypt": "^5.0.2",
54-
"@types/express": "^4.17.13",
54+
"@types/express": "^4.17.21",
5555
"@types/jest": "^28.1.8",
5656
"@types/newrelic": "^9.14.4",
5757
"@types/node": "^20.14.10",

packages/altair-api/src/auth/guards/google-oauth.guard.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ExecutionContext, Injectable } from '@nestjs/common';
1+
import { Injectable } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
3-
import { AuthGuard, IAuthModuleOptions } from '@nestjs/passport';
4-
import { Request } from 'express';
3+
import { AuthGuard } from '@nestjs/passport';
54

65
@Injectable()
76
export class GoogleOAuthGuard extends AuthGuard('google') {

packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ <h2>Login to get started</h2>
2323
>Learn more <app-icon name="info"
2424
/></a>
2525
</p>
26-
<button class="btn btn--primary" (click)="submitLogin('google')">
27-
{{ 'SIGNIN_WITH_GOOGLE' | translate }}
28-
</button>
29-
<button class="btn btn--primary" (click)="submitLogin('github')" style="margin-top: 10px;">
30-
Sign in with GitHub
31-
</button>
26+
<div class="account-dialog__signin-actions">
27+
<button class="btn btn--bordered" (click)="submitLogin('GOOGLE')">
28+
<!-- <app-icon name="google"></app-icon> -->
29+
{{ 'SIGNIN_WITH_GOOGLE' | translate }}
30+
</button>
31+
<button class="btn btn--bordered" (click)="submitLogin('GITHUB')">
32+
<app-icon name="github"></app-icon>
33+
{{ 'SIGNIN_WITH_GITHUB' | translate }}
34+
</button>
35+
</div>
3236
</div>
3337
</div>
3438
}

packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AccountState } from 'altair-graphql-core/build/types/state/account.inte
1111
import { environment } from 'environments/environment';
1212
import { apiClient } from '../../services/api/api.service';
1313
import { externalLink } from '../../utils';
14+
import { IdentityProvider } from '@altairgraphql/db';
1415

1516
@Component({
1617
selector: 'app-account-dialog',
@@ -22,10 +23,10 @@ export class AccountDialogComponent {
2223
@Input() showDialog = true;
2324
@Input() account: AccountState | undefined;
2425
@Output() toggleDialogChange = new EventEmitter<boolean>();
25-
@Output() handleLoginChange = new EventEmitter<'google' | 'github'>();
26+
@Output() handleLoginChange = new EventEmitter<IdentityProvider>();
2627
@Output() logoutChange = new EventEmitter();
2728

28-
submitLogin(provider: 'google' | 'github' = 'google') {
29+
submitLogin(provider: IdentityProvider = IdentityProvider.GOOGLE) {
2930
this.handleLoginChange.emit(provider);
3031
}
3132
async openBillingPage(e: MouseEvent) {

packages/altair-app/src/app/modules/altair/containers/altair/altair.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {
7979
} from 'altair-graphql-core/build/types/state/workspace.interface';
8080
import { getWorkspaces, WorkspaceOption } from '../../store';
8181
import { CollectionsMetaState } from 'altair-graphql-core/build/types/state/collections-meta.interfaces';
82-
import { QueryItemRevision } from '@altairgraphql/db';
82+
import { QueryItemRevision, IdentityProvider } from '@altairgraphql/db';
8383
import { consumeQueryParam } from '../../utils/url';
8484

8585
@UntilDestroy({ checkProperties: true })
@@ -844,7 +844,7 @@ export class AltairComponent {
844844
this.store.dispatch(new accountActions.LoadTeamsAction());
845845
}
846846

847-
accountLogin(provider?: 'google' | 'github') {
847+
accountLogin(provider?: IdentityProvider) {
848848
this.store.dispatch(new accountActions.LoginAccountAction({ provider }));
849849
}
850850

packages/altair-app/src/app/modules/altair/services/account/account.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ import { EMPTY, from } from 'rxjs';
55
import { isElectronApp } from '../../utils';
66
import { apiClient } from '../api/api.service';
77
import { ElectronAppService } from '../electron-app/electron-app.service';
8+
import { IdentityProvider } from '@altairgraphql/db';
89

910
@Injectable({
1011
providedIn: 'root',
1112
})
1213
export class AccountService {
1314
constructor(private electronApp: ElectronAppService) {}
1415

15-
private async signin(provider: 'google' | 'github' = 'google') {
16+
private async signin(provider: IdentityProvider = IdentityProvider.GOOGLE) {
1617
if (isElectronApp()) {
1718
const authToken = await this.electronApp.getAuthToken();
1819
return apiClient.signInWithCustomToken(authToken);
1920
}
2021

2122
return apiClient.signinWithPopup(provider);
2223
}
23-
async accountLogin(provider: 'google' | 'github' = 'google') {
24+
async accountLogin(provider: IdentityProvider = IdentityProvider.GOOGLE) {
2425
return this.signin(provider);
2526
}
2627

27-
accountLogin$(provider: 'google' | 'github' = 'google') {
28+
accountLogin$(provider: IdentityProvider = IdentityProvider.GOOGLE) {
2829
return from(this.accountLogin(provider));
2930
}
3031

packages/altair-app/src/app/modules/altair/store/account/account.action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AccountState,
44
Team,
55
} from 'altair-graphql-core/build/types/state/account.interfaces';
6+
import { IdentityProvider } from '@altairgraphql/db';
67

78
export const LOGIN_ACCOUNT = 'LOGIN_ACCOUNT';
89
export const ACCOUNT_IS_LOGGED_IN = 'ACCOUNT_IS_LOGGED_IN';
@@ -16,7 +17,7 @@ export const ACCOUNT_CHECKED_INIT = 'ACCOUNT_CHECKED_INIT';
1617
export class LoginAccountAction implements NGRXAction {
1718
readonly type = LOGIN_ACCOUNT;
1819

19-
constructor(public payload?: { provider?: 'google' | 'github' }) {}
20+
constructor(public payload?: { provider?: IdentityProvider }) {}
2021
}
2122

2223
export class AccountCheckedInitAction implements NGRXAction {

packages/altair-app/src/assets/i18n/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
"REGISTER_TAB": "Register",
231231
"LOGOUT_TEXT": "Logout",
232232
"SIGNIN_WITH_GOOGLE": "Signin with Google",
233+
"SIGNIN_WITH_GITHUB": "Signin with GitHub",
233234
"CLOUD_SYNC_TEXT": "Synced to the cloud",
234235
"TEAMS_TEXT": "Teams",
235236
"BILLING_TEXT": "Billing",

0 commit comments

Comments
 (0)