Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#2230 from IDEMSInternational/ch…
Browse files Browse the repository at this point in the history
…ore/update-firebase-bom

chore: update Firebase BoM; refactor: auth actions
  • Loading branch information
jfmcquade authored Mar 14, 2024
2 parents d44eb13 + fcd997f commit 3b8f04c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
4 changes: 1 addition & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ dependencies {
implementation project(':capacitor-cordova-android-plugins')

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.3.0')
implementation platform('com.google.firebase:firebase-bom:32.7.2')

// Declare the dependencies for the Crashlytics and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-perf'
// https://github.com/mixpanel/mixpanel-android/issues/744
implementation("com.google.firebase:firebase-iid")
}

apply from: 'capacitor.build.gradle'
Expand Down
5 changes: 5 additions & 0 deletions packages/data-models/flowTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,16 @@ export namespace FlowTypes {
"asset_pack",
"audio_end",
"audio_play",
"auth",
"changed",
"emit",
"feedback",
"go_to",
"go_to_url",
/**
* @deprecated since v0.16.27
* Use `auth: sign_in_google` instead
* */
"google_auth",
"open_external",
"pop_up",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ export class TemplateActionService extends SyncServiceBase {
);
const processor = new TemplateProcessService(this.injector);
return processor.processTemplateWithoutRender(templateToProcess);
case "google_auth":
return await this.authService.signInWithGoogle();
case "emit":
const [emit_value, emit_data] = args;
const container: TemplateContainerComponent = this.container;
Expand Down
34 changes: 33 additions & 1 deletion src/app/shared/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { filter } from "rxjs/operators";
import { IAppConfig } from "../../model";
import { AppConfigService } from "../app-config/app-config.service";
import { SyncServiceBase } from "../syncService.base";
import { TemplateActionRegistry } from "../../components/template/services/instance/template-action.registry";

@Injectable({
providedIn: "root",
Expand All @@ -15,13 +16,18 @@ export class AuthService extends SyncServiceBase {
appFields: IAppConfig["APP_FIELDS"];

// include auth import to ensure app registered
constructor(auth: Auth, private appConfigService: AppConfigService) {
constructor(
auth: Auth,
private appConfigService: AppConfigService,
private templateActionRegistry: TemplateActionRegistry
) {
super("Auth");
this.initialise();
}
private initialise() {
this.subscribeToAppConfigChanges();
this.addAuthListeners();
this.registerTemplateActionHandlers();
}

/** Return a promise that resolves after a signed in user defined */
Expand All @@ -42,6 +48,32 @@ export class AuthService extends SyncServiceBase {
return user;
}

private registerTemplateActionHandlers() {
this.templateActionRegistry.register({
auth: async ({ args }) => {
const [actionId] = args;
const childActions = {
sign_in_google: async () => await this.signInWithGoogle(),
sign_out: async () => await this.signOut(),
};
// To support deprecated "share" action (previously used to share text only),
// assume text is being shared if first arg is not an actionId
if (!(actionId in childActions)) {
console.error(`[AUTH] - No action, "${actionId}"`);
return;
}
return childActions[actionId]();
},
/**
* @deprecated since v0.16.27
* Use `auth: sign_in_google` instead
* */
google_auth: async () => {
return await this.signInWithGoogle();
},
});
}

/** Listen to auth state changes and update local subject accordingly */
private addAuthListeners() {
FirebaseAuthentication.addListener("authStateChange", ({ user }) => {
Expand Down

0 comments on commit 3b8f04c

Please sign in to comment.