Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Added new command `dataconnect:sql:shell` which run queries against Data Connect CloudSQL instances (#7778).
- Add support for deploying new blocking triggers. (#6384)
36 changes: 33 additions & 3 deletions src/deploy/functions/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export class AuthBlockingService implements Service {
if (
newConfig.triggers?.beforeCreate?.functionUri !==
config.triggers?.beforeCreate?.functionUri ||
newConfig.triggers?.beforeSignIn?.functionUri !== config.triggers?.beforeSignIn?.functionUri
newConfig.triggers?.beforeSignIn?.functionUri !==
config.triggers?.beforeSignIn?.functionUri ||
newConfig.triggers?.beforeSendEmail?.functionUri !==
config.triggers?.beforeSendEmail?.functionUri ||
newConfig.triggers?.beforeSendSms?.functionUri !== config.triggers?.beforeSendSms?.functionUri
) {
return true;
}
Expand Down Expand Up @@ -82,13 +86,31 @@ export class AuthBlockingService implements Service {
functionUri: endpoint.uri!,
},
};
} else {
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SIGN_IN_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSignIn: {
functionUri: endpoint.uri!,
},
};
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_EMAIL_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSendEmail: {
functionUri: endpoint.uri!,
},
};
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_SMS_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSendSms: {
functionUri: endpoint.uri!,
},
};
} else {
throw new FirebaseError(
`Received invalid blocking trigger event type ${endpoint.blockingTrigger.eventType}`,
);
}

newBlockingConfig.forwardInboundCredentials = {
Expand Down Expand Up @@ -121,7 +143,9 @@ export class AuthBlockingService implements Service {
const blockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project);
if (
endpoint.uri !== blockingConfig.triggers?.beforeCreate?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri
endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendSms?.functionUri
) {
return;
}
Expand All @@ -135,6 +159,12 @@ export class AuthBlockingService implements Service {
if (endpoint.uri === blockingConfig.triggers?.beforeSignIn?.functionUri) {
delete blockingConfig.triggers?.beforeSignIn;
}
if (endpoint.uri === blockingConfig.triggers?.beforeSendEmail?.functionUri) {
delete blockingConfig.triggers?.beforeSendEmail;
}
if (endpoint.uri === blockingConfig.triggers?.beforeSendSms?.functionUri) {
delete blockingConfig.triggers?.beforeSendSms;
}

await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig);
}
Expand Down
2 changes: 2 additions & 0 deletions src/deploy/functions/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ const EVENT_SERVICE_MAPPING: Record<events.Event, Service> = {
"google.firebase.firebasealerts.alerts.v1.published": firebaseAlertsService,
"providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendEmail": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendSms": authBlockingService,
"google.firebase.database.ref.v1.written": databaseService,
"google.firebase.database.ref.v1.created": databaseService,
"google.firebase.database.ref.v1.updated": databaseService,
Expand Down
5 changes: 5 additions & 0 deletions src/functions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export const BLOCKING_LABEL = "deployment-blocking";
export const BLOCKING_LABEL_KEY_TO_EVENT: Record<string, (typeof AUTH_BLOCKING_EVENTS)[number]> = {
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
"before-send-email": "providers/cloud.auth/eventTypes/user.beforeSendEmail",
"before-send-sms": "providers/cloud.auth/eventTypes/user.beforeSendSms",
};

export const BLOCKING_EVENT_TO_LABEL_KEY: Record<(typeof AUTH_BLOCKING_EVENTS)[number], string> = {
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
"providers/cloud.auth/eventTypes/user.beforeSendEmail": "before-send-email",
"providers/cloud.auth/eventTypes/user.beforeSendSms": "before-send-sms",
};
11 changes: 10 additions & 1 deletion src/functions/events/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ export const BEFORE_CREATE_EVENT = "providers/cloud.auth/eventTypes/user.beforeC

export const BEFORE_SIGN_IN_EVENT = "providers/cloud.auth/eventTypes/user.beforeSignIn";

export const AUTH_BLOCKING_EVENTS = [BEFORE_CREATE_EVENT, BEFORE_SIGN_IN_EVENT] as const;
export const BEFORE_SEND_EMAIL_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendEmail";

export const BEFORE_SEND_SMS_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendSms";

export const AUTH_BLOCKING_EVENTS = [
BEFORE_CREATE_EVENT,
BEFORE_SIGN_IN_EVENT,
BEFORE_SEND_EMAIL_EVENT,
BEFORE_SEND_SMS_EVENT,
] as const;

export type Event = (typeof AUTH_BLOCKING_EVENTS)[number];
2 changes: 2 additions & 0 deletions src/gcp/identityPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface BlockingFunctionsConfig {
triggers?: {
beforeCreate?: BlockingFunctionsEventDetails;
beforeSignIn?: BlockingFunctionsEventDetails;
beforeSendEmail?: BlockingFunctionsEventDetails;
beforeSendSms?: BlockingFunctionsEventDetails;
};
forwardInboundCredentials?: BlockingFunctionsOptions;
}
Expand Down