Added transtitions in sign-in flow and implemented Google OAuth
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -44,6 +44,7 @@
|
||||
"@angular/build": "^21.2.6",
|
||||
"@angular/cli": "^21.2.6",
|
||||
"@angular/compiler-cli": "^21.2.0",
|
||||
"@types/google.accounts": "^0.0.18",
|
||||
"jsdom": "^28.0.0",
|
||||
"less": "^4.6.4",
|
||||
"prettier": "^3.8.1",
|
||||
@@ -5180,6 +5181,13 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/google.accounts": {
|
||||
"version": "0.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@types/google.accounts/-/google.accounts-0.0.18.tgz",
|
||||
"integrity": "sha512-yHaPznll97ZnMJlPABHyeiIlLn3u6gQaUjA5k/O9lrrpgFB9VT10CKPLuKM0qTHMl50uXpW5sIcG+utm8jMOHw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/linkify-it": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
"@angular/build": "^21.2.6",
|
||||
"@angular/cli": "^21.2.6",
|
||||
"@angular/compiler-cli": "^21.2.0",
|
||||
"@types/google.accounts": "^0.0.18",
|
||||
"jsdom": "^28.0.0",
|
||||
"less": "^4.6.4",
|
||||
"prettier": "^3.8.1",
|
||||
|
||||
16
src/app/google-oauth.spec.ts
Normal file
16
src/app/google-oauth.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GoogleOAuth } from './google-oauth';
|
||||
|
||||
describe('GoogleOAuth', () => {
|
||||
let service: GoogleOAuth;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(GoogleOAuth);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
30
src/app/google-oauth.ts
Normal file
30
src/app/google-oauth.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { inject, Injectable, NgZone } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GoogleOAuth {
|
||||
private ngZone = inject(NgZone);
|
||||
private codeClient?: google.accounts.oauth2.CodeClient;
|
||||
private codeSubject = new Subject<string>();
|
||||
|
||||
readonly code$ = this.codeSubject.asObservable();
|
||||
|
||||
init(clientId: string): void {
|
||||
this.codeClient = google.accounts.oauth2.initCodeClient({
|
||||
client_id: clientId,
|
||||
scope: 'openid email profile',
|
||||
ux_mode: 'popup',
|
||||
callback: (response) => {
|
||||
if (response.code) {
|
||||
this.ngZone.run(() => this.codeSubject.next(response.code));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openSignIn(): void {
|
||||
this.codeClient?.requestCode();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<main id="holder">
|
||||
@switch (page()) {
|
||||
@case ('initial') {
|
||||
<form [formGroup]="signInForm" tuiAppearance="floating" id="initial">
|
||||
<form [formGroup]="signInForm" tuiAppearance="floating" id="initial" animate.enter="slide-in-right"
|
||||
animate.leave="slide-out-left">
|
||||
<header>
|
||||
<h1>{{ "signIn.initial.formTitle"|translate }}</h1>
|
||||
<span>{{ "signIn.initial.formSubtitle"|translate }}</span>
|
||||
@@ -12,7 +13,8 @@
|
||||
<label tuiLabel>{{ "signIn.initial.mainInput.label"|translate }}</label>
|
||||
|
||||
<input (input)="checkAuthMethods(signInForm.controls['unameMailPhone'].value)"
|
||||
formControlName="unameMailPhone" tuiInput placeholder="{{'signIn.mainInput.placeholder'|translate}}">
|
||||
formControlName="unameMailPhone" tuiInput
|
||||
placeholder="{{'signIn.initial.mainInput.placeholder'|translate}}">
|
||||
</tui-textfield>
|
||||
@if (signInForm.controls["unameMailPhone"].dirty) {
|
||||
@if (signInForm.controls["unameMailPhone"].hasError("required")) {
|
||||
@@ -30,7 +32,7 @@
|
||||
</form>
|
||||
}
|
||||
@case ('methodChoose') {
|
||||
<form id="methodChoose">
|
||||
<form id="methodChoose" animate.enter="slide-in-right" animate.leave="slide-out-left">
|
||||
<header>
|
||||
@if (isMultistep()) {
|
||||
<h1>{{ "signIn.methodChoose.formTitleAlt"|translate }}</h1>
|
||||
@@ -54,7 +56,8 @@
|
||||
</button>
|
||||
}
|
||||
@if (challenge()!.factorsTracker["EMAIL"] != null) {
|
||||
<button type="button" [disabled]="challenge()!.factorsTracker['EMAIL'].status == 'SUCCESS' || pendingAction()" tuiButton
|
||||
<button type="button"
|
||||
[disabled]="challenge()!.factorsTracker['EMAIL'].status == 'SUCCESS' || pendingAction()" tuiButton
|
||||
appearance="secondary" class="method" (click)="this.requestCredential('EMAIL')">
|
||||
<tui-icon icon="@tui.mail"></tui-icon>
|
||||
<div>
|
||||
@@ -70,7 +73,9 @@
|
||||
<span class="desc">{{ "signIn.methodChoose.methods.sms.desc"|translate }}</span>
|
||||
</div>
|
||||
</button>
|
||||
<button tuiButton appearance="secondary" class="method">
|
||||
@if (challenge()!.factorsTracker["GOOGLE"] != null) {
|
||||
<button type="button" tuiButton appearance="secondary" class="method"
|
||||
(click)="this.googleOAuth.openSignIn();" [disabled]="challenge()!.factorsTracker['GOOGLE'].status == 'SUCCESS' || pendingAction()">
|
||||
<fa-icon [icon]="faGoogle" style="font-size: 25px; margin-left: -5px"></fa-icon>
|
||||
|
||||
<div>
|
||||
@@ -78,6 +83,7 @@
|
||||
<span class="desc">{{ "signIn.methodChoose.methods.google.desc"|translate }}</span>
|
||||
</div>
|
||||
</button>
|
||||
}
|
||||
<button tuiButton appearance="secondary" class="method">
|
||||
<fa-icon [icon]="faApple" style="font-size: 30px; margin-left: -7px"></fa-icon>
|
||||
<div>
|
||||
@@ -90,7 +96,8 @@
|
||||
</form>
|
||||
}
|
||||
@case ('passwordAuth') {
|
||||
<form [formGroup]="authForm" tuiAppearance="floating" id="passwordAuth">
|
||||
<form [formGroup]="authForm" tuiAppearance="floating" id="passwordAuth" animate.enter="slide-in-right"
|
||||
animate.leave="slide-out-left">
|
||||
<header>
|
||||
<h1>{{ "signIn.passwordAuth.formTitle"|translate }}</h1>
|
||||
<span>{{ "signIn.passwordAuth.formSubtitle"|translate }}</span>
|
||||
@@ -120,7 +127,8 @@
|
||||
</form>
|
||||
}
|
||||
@case ('emailAuth') {
|
||||
<form [formGroup]="authForm" tuiAppearance="floating" id="emailAuth">
|
||||
<form [formGroup]="authForm" tuiAppearance="floating" id="emailAuth" animate.enter="slide-in-right"
|
||||
animate.leave="slide-out-left">
|
||||
<header>
|
||||
<h1>{{ "signIn.emailAuth.formTitle"|translate }}</h1>
|
||||
<span>{{ "signIn.emailAuth.formSubtitle"|translate }}</span>
|
||||
@@ -149,7 +157,7 @@
|
||||
</form>
|
||||
}
|
||||
@case ('ok') {
|
||||
{{challenge()|json}}
|
||||
<h1>Received Chtn identity token, auth flow finished</h1>
|
||||
}
|
||||
}
|
||||
</main>
|
||||
|
||||
@@ -4,7 +4,26 @@
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
|
||||
.slide-in-right {
|
||||
animation: slideInRight 250ms ease-out forwards;
|
||||
}
|
||||
|
||||
.slide-out-left {
|
||||
animation: slideOutLeft 200ms ease-in forwards;
|
||||
}
|
||||
|
||||
@keyframes slideInRight {
|
||||
from { opacity: 0; transform: translateX(-8px); }
|
||||
to { opacity: 1; transform: translateX(0); }
|
||||
}
|
||||
|
||||
@keyframes slideOutLeft {
|
||||
from { opacity: 1; transform: translateX(0); }
|
||||
to { opacity: 0; transform: translateX(8px); }
|
||||
}
|
||||
|
||||
form {
|
||||
position: absolute;
|
||||
width: 35%;
|
||||
max-height: 65%;
|
||||
border-radius: 35px;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export const environment = {
|
||||
version: "3.0-beta11",
|
||||
api_url: "http://localhost:3000",
|
||||
cdn_url: "http://localhost:4000",
|
||||
ws_url: "ws://localhost:3000",
|
||||
version: '3.0-beta11',
|
||||
api_url: 'http://localhost:3000',
|
||||
cdn_url: 'http://localhost:4000',
|
||||
ws_url: 'ws://localhost:3000',
|
||||
// Google OAuth
|
||||
google_client_id: '21430884719-vjmecc7ofnfp82hmb22hba323gr4r7p7.apps.googleusercontent.com',
|
||||
};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export const environment = {
|
||||
version: "3.0-beta11",
|
||||
api_url: "https://api.chatenium.hu",
|
||||
cdn_url: "https://cdn.chatenium.hu",
|
||||
ws_url: "wss://api.chatenium.hu",
|
||||
version: '3.0-beta11',
|
||||
api_url: 'https://api.chatenium.hu',
|
||||
cdn_url: 'https://cdn.chatenium.hu',
|
||||
ws_url: 'wss://api.chatenium.hu',
|
||||
// Google OAuth
|
||||
google_client_id: '21430884719-vjmecc7ofnfp82hmb22hba323gr4r7p7.apps.googleusercontent.com',
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
<link rel="manifest" href="manifest.webmanifest">
|
||||
<script src="https://accounts.google.com/gsi/client" async defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": []
|
||||
"types": ["google.accounts"]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
|
||||
Reference in New Issue
Block a user