Finished implementing sign-in procedure for API/v3. Updated guards to V3 and started rewriting /chat too. UserData updating and multi-user support is TODO
This commit is contained in:
@@ -1,17 +1,27 @@
|
||||
import { Component, computed, inject, OnInit, signal } from '@angular/core';
|
||||
import {TuiAppearance, TuiButton, TuiError, TuiErrorDirective, TuiGroup, TuiIcon, TuiInput, TuiTextfield} from '@taiga-ui/core';
|
||||
import {
|
||||
TuiAlertService,
|
||||
TuiAppearance,
|
||||
TuiButton,
|
||||
TuiError,
|
||||
TuiErrorDirective,
|
||||
TuiGroup,
|
||||
TuiIcon,
|
||||
TuiInput,
|
||||
TuiNotificationService,
|
||||
TuiTextfield,
|
||||
} from '@taiga-ui/core';
|
||||
import {TranslatePipe} from '@ngx-translate/core';
|
||||
import {TuiButtonGroup, TuiPassword} from '@taiga-ui/kit';
|
||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {AuthService} from '@chatenium/chatenium-sdk/services/authService';
|
||||
import {AuthMethods} from '@chatenium/chatenium-sdk/domain/authService.schema';
|
||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
||||
import {ServiceManager} from '../service-manager';
|
||||
import {IndexedDB} from '../storage/indexed-db';
|
||||
import {PublicUserData} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||
import {Router} from '@angular/router';
|
||||
import { CHATENIUM_SDK } from '../chatenium.token';
|
||||
import { AuthChallenge, Challenge } from 'chatenium-sdk-preview';
|
||||
import { AuthChallenge, Challenge, SignInReq, SuccessfulAuthResp } from 'chatenium-sdk-preview';
|
||||
import { TuiItemGroup } from '@taiga-ui/layout';
|
||||
import { faApple, faGoogle } from '@fortawesome/free-brands-svg-icons';
|
||||
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
||||
@@ -19,6 +29,9 @@ import { JsonPipe } from '@angular/common';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { GoogleOAuth } from '../google-oauth';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { SessionManager } from '../session-manager';
|
||||
import { Platform } from '@angular/cdk/platform';
|
||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||
|
||||
@Component({
|
||||
selector: 'app-signin',
|
||||
@@ -42,6 +55,9 @@ import { environment } from '../../environments/environment';
|
||||
export class SignIn implements OnInit {
|
||||
SDK = inject(CHATENIUM_SDK);
|
||||
googleOAuth = inject(GoogleOAuth);
|
||||
sessionManager = inject(SessionManager);
|
||||
device = inject(DeviceDetectorService);
|
||||
notification = inject(TuiNotificationService);
|
||||
|
||||
private googleSub?: Subscription;
|
||||
|
||||
@@ -125,6 +141,7 @@ export class SignIn implements OnInit {
|
||||
this.page.set('methodChoose');
|
||||
this.authForm.reset();
|
||||
} else {
|
||||
await this.signIn(resp.authIdentityToken);
|
||||
this.page.set('ok');
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -135,6 +152,20 @@ export class SignIn implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
private async signIn(authIdentityToken: string) {
|
||||
try {
|
||||
const resp = await this.SDK.auth.signIn(authIdentityToken, {
|
||||
os: this.device.deviceInfo().os,
|
||||
frontend: "nexum"
|
||||
})
|
||||
const data = resp.data as SuccessfulAuthResp;
|
||||
await this.sessionManager.addSession(data.refreshToken, data.accessToken, data.userId);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.notification.open('SignIn Failed', { appearance: "negative" }).subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
async requestCredential(methodName: string) {
|
||||
this.pendingAction.set(true);
|
||||
if (this.challengeApi != null) {
|
||||
|
||||
Reference in New Issue
Block a user