1- import { registerPlugin , WebPlugin } from '@capacitor/core' ;
1+ import { WebPlugin } from '@capacitor/core' ;
22import { GoogleAuthPlugin } from './definitions' ;
33import { User , Authentication } from './user' ;
44
@@ -18,24 +18,10 @@ export class GoogleAuthWeb extends WebPlugin implements GoogleAuthPlugin {
1818 }
1919
2020 constructor ( ) {
21- super ( {
22- name : 'GoogleAuth' ,
23- platforms : [ 'web' ]
24- } ) ;
25-
26- if ( ! this . webConfigured )
27- return ;
28-
29- this . gapiLoaded = new Promise ( resolve => {
30- // HACK: Relying on window object, can't get property in gapi.load callback
31- ( window as any ) . gapiResolve = resolve ;
32- this . initialize ( ) ;
33- } ) ;
34-
35- this . addUserChangeListener ( ) ;
21+ super ( ) ;
3622 }
3723
38- initialize ( ) {
24+ loadScript ( ) {
3925 var head = document . getElementsByTagName ( 'head' ) [ 0 ] ;
4026 var script = document . createElement ( 'script' ) ;
4127 script . type = 'text/javascript' ;
@@ -46,6 +32,19 @@ export class GoogleAuthWeb extends WebPlugin implements GoogleAuthPlugin {
4632 head . appendChild ( script ) ;
4733 }
4834
35+ init ( ) {
36+ if ( ! this . webConfigured )
37+ return ;
38+
39+ this . gapiLoaded = new Promise ( resolve => {
40+ // HACK: Relying on window object, can't get property in gapi.load callback
41+ ( window as any ) . gapiResolve = resolve ;
42+ this . loadScript ( ) ;
43+ } ) ;
44+
45+ this . addUserChangeListener ( ) ;
46+ }
47+
4948 platformJsLoaded ( ) {
5049 gapi . load ( 'auth2' , ( ) => {
5150 const clientConfig : gapi . auth2 . ClientConfig = {
@@ -135,8 +134,3 @@ export class GoogleAuthWeb extends WebPlugin implements GoogleAuthPlugin {
135134 return user ;
136135 }
137136}
138-
139- const GoogleAuth = registerPlugin ( 'GoogleAuth' , { web : new GoogleAuthWeb ( ) } ) ;
140-
141- export { GoogleAuth } ;
142-
0 commit comments