Added transtitions in sign-in flow and implemented Google OAuth
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user