Added transtitions in sign-in flow and implemented Google OAuth

This commit is contained in:
Noel Maróti
2026-11-24 20:01:51 +01:00
parent eeee9d5154
commit 086d27c9a4
11 changed files with 150 additions and 31 deletions

View File

@@ -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;