Added transtitions in sign-in flow and implemented Google OAuth
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import { Component, computed, inject, OnInit, signal } from '@angular/core';
|
||||
import {TuiAppearance, TuiButton, TuiError, TuiErrorDirective, TuiGroup, TuiIcon, TuiInput, TuiTextfield} from '@taiga-ui/core';
|
||||
import {TranslatePipe} from '@ngx-translate/core';
|
||||
import {TuiButtonGroup, TuiPassword} from '@taiga-ui/kit';
|
||||
@@ -16,6 +16,9 @@ import { TuiItemGroup } from '@taiga-ui/layout';
|
||||
import { faApple, faGoogle } from '@fortawesome/free-brands-svg-icons';
|
||||
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
||||
import { JsonPipe } from '@angular/common';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { GoogleOAuth } from '../google-oauth';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Component({
|
||||
selector: 'app-signin',
|
||||
@@ -25,13 +28,10 @@ import { JsonPipe } from '@angular/common';
|
||||
TuiTextfield,
|
||||
TuiInput,
|
||||
TuiButton,
|
||||
TuiButtonGroup,
|
||||
TuiPassword,
|
||||
TuiIcon,
|
||||
ReactiveFormsModule,
|
||||
TuiErrorDirective,
|
||||
TuiError,
|
||||
TuiItemGroup,
|
||||
TuiGroup,
|
||||
FaIconComponent,
|
||||
JsonPipe,
|
||||
@@ -41,6 +41,9 @@ import { JsonPipe } from '@angular/common';
|
||||
})
|
||||
export class SignIn implements OnInit {
|
||||
SDK = inject(CHATENIUM_SDK);
|
||||
googleOAuth = inject(GoogleOAuth);
|
||||
|
||||
private googleSub?: Subscription;
|
||||
|
||||
challengeApi: AuthChallenge | null = null;
|
||||
challenge = signal<Challenge | null>(null);
|
||||
@@ -53,7 +56,9 @@ export class SignIn implements OnInit {
|
||||
methods = signal<AuthMethods>({ sms: false, email: false, password: false });
|
||||
|
||||
pendingAction = signal(false);
|
||||
page = signal<'initial' | 'methodChoose' | 'passwordAuth' | 'emailAuth' | 'smsAuth' | 'ok'>('initial');
|
||||
page = signal<'initial' | 'methodChoose' | 'passwordAuth' | 'emailAuth' | 'smsAuth' | 'ok'>(
|
||||
'initial',
|
||||
);
|
||||
isMultistep = signal(false);
|
||||
|
||||
signInForm = new FormGroup({
|
||||
@@ -120,7 +125,7 @@ export class SignIn implements OnInit {
|
||||
this.page.set('methodChoose');
|
||||
this.authForm.reset();
|
||||
} else {
|
||||
this.page.set("ok")
|
||||
this.page.set('ok');
|
||||
}
|
||||
} catch (e) {
|
||||
this.pendingAction.set(false);
|
||||
@@ -139,7 +144,7 @@ export class SignIn implements OnInit {
|
||||
this.pendingAction.set(false);
|
||||
if (resp.authIdentityToken == null) {
|
||||
this.isMultistep.set(true);
|
||||
this.page.set(methodName == "EMAIL" ? 'emailAuth' : 'smsAuth');
|
||||
this.page.set(methodName == 'EMAIL' ? 'emailAuth' : 'smsAuth');
|
||||
}
|
||||
} catch (e) {
|
||||
this.pendingAction.set(false);
|
||||
@@ -149,8 +154,35 @@ export class SignIn implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.indexedDb.openDatabase();
|
||||
|
||||
this.googleSub = this.googleOAuth.code$.subscribe((code) => {
|
||||
this.verifyMethod("GOOGLE", code);
|
||||
});
|
||||
|
||||
this.waitForGoogle().then(() => {
|
||||
this.googleOAuth.init(environment.google_client_id);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.googleSub?.unsubscribe();
|
||||
}
|
||||
|
||||
private waitForGoogle(): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
if (typeof google !== 'undefined' && google.accounts?.oauth2) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
const timer = setInterval(() => {
|
||||
if (typeof google !== 'undefined' && google.accounts?.oauth2) {
|
||||
clearInterval(timer);
|
||||
resolve();
|
||||
}
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
|
||||
protected readonly faGoogle = faGoogle;
|
||||
|
||||
Reference in New Issue
Block a user