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/build": "^21.2.6",
|
||||||
"@angular/cli": "^21.2.6",
|
"@angular/cli": "^21.2.6",
|
||||||
"@angular/compiler-cli": "^21.2.0",
|
"@angular/compiler-cli": "^21.2.0",
|
||||||
|
"@types/google.accounts": "^0.0.18",
|
||||||
"jsdom": "^28.0.0",
|
"jsdom": "^28.0.0",
|
||||||
"less": "^4.6.4",
|
"less": "^4.6.4",
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
@@ -5180,6 +5181,13 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"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": {
|
"node_modules/@types/linkify-it": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
"@angular/build": "^21.2.6",
|
"@angular/build": "^21.2.6",
|
||||||
"@angular/cli": "^21.2.6",
|
"@angular/cli": "^21.2.6",
|
||||||
"@angular/compiler-cli": "^21.2.0",
|
"@angular/compiler-cli": "^21.2.0",
|
||||||
|
"@types/google.accounts": "^0.0.18",
|
||||||
"jsdom": "^28.0.0",
|
"jsdom": "^28.0.0",
|
||||||
"less": "^4.6.4",
|
"less": "^4.6.4",
|
||||||
"prettier": "^3.8.1",
|
"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">
|
<main id="holder">
|
||||||
@switch (page()) {
|
@switch (page()) {
|
||||||
@case ('initial') {
|
@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>
|
<header>
|
||||||
<h1>{{ "signIn.initial.formTitle"|translate }}</h1>
|
<h1>{{ "signIn.initial.formTitle"|translate }}</h1>
|
||||||
<span>{{ "signIn.initial.formSubtitle"|translate }}</span>
|
<span>{{ "signIn.initial.formSubtitle"|translate }}</span>
|
||||||
@@ -12,7 +13,8 @@
|
|||||||
<label tuiLabel>{{ "signIn.initial.mainInput.label"|translate }}</label>
|
<label tuiLabel>{{ "signIn.initial.mainInput.label"|translate }}</label>
|
||||||
|
|
||||||
<input (input)="checkAuthMethods(signInForm.controls['unameMailPhone'].value)"
|
<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>
|
</tui-textfield>
|
||||||
@if (signInForm.controls["unameMailPhone"].dirty) {
|
@if (signInForm.controls["unameMailPhone"].dirty) {
|
||||||
@if (signInForm.controls["unameMailPhone"].hasError("required")) {
|
@if (signInForm.controls["unameMailPhone"].hasError("required")) {
|
||||||
@@ -30,7 +32,7 @@
|
|||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@case ('methodChoose') {
|
@case ('methodChoose') {
|
||||||
<form id="methodChoose">
|
<form id="methodChoose" animate.enter="slide-in-right" animate.leave="slide-out-left">
|
||||||
<header>
|
<header>
|
||||||
@if (isMultistep()) {
|
@if (isMultistep()) {
|
||||||
<h1>{{ "signIn.methodChoose.formTitleAlt"|translate }}</h1>
|
<h1>{{ "signIn.methodChoose.formTitleAlt"|translate }}</h1>
|
||||||
@@ -54,7 +56,8 @@
|
|||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
@if (challenge()!.factorsTracker["EMAIL"] != null) {
|
@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')">
|
appearance="secondary" class="method" (click)="this.requestCredential('EMAIL')">
|
||||||
<tui-icon icon="@tui.mail"></tui-icon>
|
<tui-icon icon="@tui.mail"></tui-icon>
|
||||||
<div>
|
<div>
|
||||||
@@ -70,14 +73,17 @@
|
|||||||
<span class="desc">{{ "signIn.methodChoose.methods.sms.desc"|translate }}</span>
|
<span class="desc">{{ "signIn.methodChoose.methods.sms.desc"|translate }}</span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
<button tuiButton appearance="secondary" class="method">
|
@if (challenge()!.factorsTracker["GOOGLE"] != null) {
|
||||||
<fa-icon [icon]="faGoogle" style="font-size: 25px; margin-left: -5px"></fa-icon>
|
<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>
|
<div>
|
||||||
<span class="title">{{ "signIn.methodChoose.methods.google.title"|translate }}</span>
|
<span class="title">{{ "signIn.methodChoose.methods.google.title"|translate }}</span>
|
||||||
<span class="desc">{{ "signIn.methodChoose.methods.google.desc"|translate }}</span>
|
<span class="desc">{{ "signIn.methodChoose.methods.google.desc"|translate }}</span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
}
|
||||||
<button tuiButton appearance="secondary" class="method">
|
<button tuiButton appearance="secondary" class="method">
|
||||||
<fa-icon [icon]="faApple" style="font-size: 30px; margin-left: -7px"></fa-icon>
|
<fa-icon [icon]="faApple" style="font-size: 30px; margin-left: -7px"></fa-icon>
|
||||||
<div>
|
<div>
|
||||||
@@ -90,7 +96,8 @@
|
|||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@case ('passwordAuth') {
|
@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>
|
<header>
|
||||||
<h1>{{ "signIn.passwordAuth.formTitle"|translate }}</h1>
|
<h1>{{ "signIn.passwordAuth.formTitle"|translate }}</h1>
|
||||||
<span>{{ "signIn.passwordAuth.formSubtitle"|translate }}</span>
|
<span>{{ "signIn.passwordAuth.formSubtitle"|translate }}</span>
|
||||||
@@ -120,7 +127,8 @@
|
|||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@case ('emailAuth') {
|
@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>
|
<header>
|
||||||
<h1>{{ "signIn.emailAuth.formTitle"|translate }}</h1>
|
<h1>{{ "signIn.emailAuth.formTitle"|translate }}</h1>
|
||||||
<span>{{ "signIn.emailAuth.formSubtitle"|translate }}</span>
|
<span>{{ "signIn.emailAuth.formSubtitle"|translate }}</span>
|
||||||
@@ -149,7 +157,7 @@
|
|||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@case ('ok') {
|
@case ('ok') {
|
||||||
{{challenge()|json}}
|
<h1>Received Chtn identity token, auth flow finished</h1>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -4,7 +4,26 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100vh;
|
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 {
|
form {
|
||||||
|
position: absolute;
|
||||||
width: 35%;
|
width: 35%;
|
||||||
max-height: 65%;
|
max-height: 65%;
|
||||||
border-radius: 35px;
|
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 {TuiAppearance, TuiButton, TuiError, TuiErrorDirective, TuiGroup, TuiIcon, TuiInput, TuiTextfield} from '@taiga-ui/core';
|
||||||
import {TranslatePipe} from '@ngx-translate/core';
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
import {TuiButtonGroup, TuiPassword} from '@taiga-ui/kit';
|
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 { faApple, faGoogle } from '@fortawesome/free-brands-svg-icons';
|
||||||
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
||||||
import { JsonPipe } from '@angular/common';
|
import { JsonPipe } from '@angular/common';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { GoogleOAuth } from '../google-oauth';
|
||||||
|
import { environment } from '../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-signin',
|
selector: 'app-signin',
|
||||||
@@ -25,13 +28,10 @@ import { JsonPipe } from '@angular/common';
|
|||||||
TuiTextfield,
|
TuiTextfield,
|
||||||
TuiInput,
|
TuiInput,
|
||||||
TuiButton,
|
TuiButton,
|
||||||
TuiButtonGroup,
|
|
||||||
TuiPassword,
|
TuiPassword,
|
||||||
TuiIcon,
|
TuiIcon,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
TuiErrorDirective,
|
|
||||||
TuiError,
|
TuiError,
|
||||||
TuiItemGroup,
|
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
FaIconComponent,
|
FaIconComponent,
|
||||||
JsonPipe,
|
JsonPipe,
|
||||||
@@ -41,6 +41,9 @@ import { JsonPipe } from '@angular/common';
|
|||||||
})
|
})
|
||||||
export class SignIn implements OnInit {
|
export class SignIn implements OnInit {
|
||||||
SDK = inject(CHATENIUM_SDK);
|
SDK = inject(CHATENIUM_SDK);
|
||||||
|
googleOAuth = inject(GoogleOAuth);
|
||||||
|
|
||||||
|
private googleSub?: Subscription;
|
||||||
|
|
||||||
challengeApi: AuthChallenge | null = null;
|
challengeApi: AuthChallenge | null = null;
|
||||||
challenge = signal<Challenge | 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 });
|
methods = signal<AuthMethods>({ sms: false, email: false, password: false });
|
||||||
|
|
||||||
pendingAction = signal(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);
|
isMultistep = signal(false);
|
||||||
|
|
||||||
signInForm = new FormGroup({
|
signInForm = new FormGroup({
|
||||||
@@ -120,7 +125,7 @@ export class SignIn implements OnInit {
|
|||||||
this.page.set('methodChoose');
|
this.page.set('methodChoose');
|
||||||
this.authForm.reset();
|
this.authForm.reset();
|
||||||
} else {
|
} else {
|
||||||
this.page.set("ok")
|
this.page.set('ok');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.pendingAction.set(false);
|
this.pendingAction.set(false);
|
||||||
@@ -139,7 +144,7 @@ export class SignIn implements OnInit {
|
|||||||
this.pendingAction.set(false);
|
this.pendingAction.set(false);
|
||||||
if (resp.authIdentityToken == null) {
|
if (resp.authIdentityToken == null) {
|
||||||
this.isMultistep.set(true);
|
this.isMultistep.set(true);
|
||||||
this.page.set(methodName == "EMAIL" ? 'emailAuth' : 'smsAuth');
|
this.page.set(methodName == 'EMAIL' ? 'emailAuth' : 'smsAuth');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.pendingAction.set(false);
|
this.pendingAction.set(false);
|
||||||
@@ -149,8 +154,35 @@ export class SignIn implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
async ngOnInit(): Promise<void> {
|
||||||
this.indexedDb.openDatabase();
|
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;
|
protected readonly faGoogle = faGoogle;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
version: "3.0-beta11",
|
version: '3.0-beta11',
|
||||||
api_url: "http://localhost:3000",
|
api_url: 'http://localhost:3000',
|
||||||
cdn_url: "http://localhost:4000",
|
cdn_url: 'http://localhost:4000',
|
||||||
ws_url: "ws://localhost:3000",
|
ws_url: 'ws://localhost:3000',
|
||||||
|
// Google OAuth
|
||||||
|
google_client_id: '21430884719-vjmecc7ofnfp82hmb22hba323gr4r7p7.apps.googleusercontent.com',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
version: "3.0-beta11",
|
version: '3.0-beta11',
|
||||||
api_url: "https://api.chatenium.hu",
|
api_url: 'https://api.chatenium.hu',
|
||||||
cdn_url: "https://cdn.chatenium.hu",
|
cdn_url: 'https://cdn.chatenium.hu',
|
||||||
ws_url: "wss://api.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="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="icon" type="image/x-icon" href="favicon.ico">
|
||||||
<link rel="manifest" href="manifest.webmanifest">
|
<link rel="manifest" href="manifest.webmanifest">
|
||||||
|
<script src="https://accounts.google.com/gsi/client" async defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<app-root></app-root>
|
<app-root></app-root>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./out-tsc/app",
|
"outDir": "./out-tsc/app",
|
||||||
"types": []
|
"types": ["google.accounts"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user