@@ -6,6 +6,7 @@ import { filter } from "rxjs/operators";
6
6
import { IAppConfig } from "../../model" ;
7
7
import { AppConfigService } from "../app-config/app-config.service" ;
8
8
import { SyncServiceBase } from "../syncService.base" ;
9
+ import { TemplateActionRegistry } from "../../components/template/services/instance/template-action.registry" ;
9
10
10
11
@Injectable ( {
11
12
providedIn : "root" ,
@@ -15,13 +16,18 @@ export class AuthService extends SyncServiceBase {
15
16
appFields : IAppConfig [ "APP_FIELDS" ] ;
16
17
17
18
// include auth import to ensure app registered
18
- constructor ( auth : Auth , private appConfigService : AppConfigService ) {
19
+ constructor (
20
+ auth : Auth ,
21
+ private appConfigService : AppConfigService ,
22
+ private templateActionRegistry : TemplateActionRegistry
23
+ ) {
19
24
super ( "Auth" ) ;
20
25
this . initialise ( ) ;
21
26
}
22
27
private initialise ( ) {
23
28
this . subscribeToAppConfigChanges ( ) ;
24
29
this . addAuthListeners ( ) ;
30
+ this . registerTemplateActionHandlers ( ) ;
25
31
}
26
32
27
33
/** Return a promise that resolves after a signed in user defined */
@@ -42,6 +48,32 @@ export class AuthService extends SyncServiceBase {
42
48
return user ;
43
49
}
44
50
51
+ private registerTemplateActionHandlers ( ) {
52
+ this . templateActionRegistry . register ( {
53
+ auth : async ( { args } ) => {
54
+ const [ actionId ] = args ;
55
+ const childActions = {
56
+ sign_in_google : async ( ) => await this . signInWithGoogle ( ) ,
57
+ sign_out : async ( ) => await this . signOut ( ) ,
58
+ } ;
59
+ // To support deprecated "share" action (previously used to share text only),
60
+ // assume text is being shared if first arg is not an actionId
61
+ if ( ! ( actionId in childActions ) ) {
62
+ console . error ( `[AUTH] - No action, "${ actionId } "` ) ;
63
+ return ;
64
+ }
65
+ return childActions [ actionId ] ( ) ;
66
+ } ,
67
+ /**
68
+ * @deprecated since v0.16.27
69
+ * Use `auth: sign_in_google` instead
70
+ * */
71
+ google_auth : async ( ) => {
72
+ return await this . signInWithGoogle ( ) ;
73
+ } ,
74
+ } ) ;
75
+ }
76
+
45
77
/** Listen to auth state changes and update local subject accordingly */
46
78
private addAuthListeners ( ) {
47
79
FirebaseAuthentication . addListener ( "authStateChange" , ( { user } ) => {
0 commit comments