Skip to content

Commit

Permalink
Remove Auth Domain on Channel Delete (#2712)
Browse files Browse the repository at this point in the history
* added remove ability

* lint fix

* pr fixes

* lint

* add change log

* remove extra space
  • Loading branch information
dahliasalem committed Oct 15, 2020
1 parent 2b01ab6 commit c6ab336
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- Release Firestore emulator v1.11.9: Fixes != and not-in operators.
- Add endpoints to enable/disable background triggers in the Cloud Functions emulator.
- Fixes `TypeError` that arises when trying to deploy with Firebase Hosting targets that don't exist in the project's firebase.json (#1232).
- Updates `firebase hosting:channel:delete` to remove the channel from the authorized domains list.
6 changes: 5 additions & 1 deletion src/commands/hosting-channel-delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bold, underline } from "cli-color";

import { Command } from "../command";
import { deleteChannel, normalizeName } from "../hosting/api";
import { deleteChannel, normalizeName, getChannel, removeAuthDomain } from "../hosting/api";
import { requirePermissions } from "../requirePermissions";
import * as getProjectId from "../getProjectId";
import * as requireConfig from "../requireConfig";
Expand Down Expand Up @@ -33,6 +33,7 @@ export default new Command("hosting:channel:delete <channelId>")
const siteId = options.site || (await getInstanceId(options));

channelId = normalizeName(channelId);
const channel = await getChannel(projectId, siteId, channelId);

let confirmed = Boolean(options.force);
if (!confirmed) {
Expand All @@ -50,6 +51,9 @@ export default new Command("hosting:channel:delete <channelId>")
}

await deleteChannel(projectId, siteId, channelId);
if (channel) {
await removeAuthDomain(projectId, channel.url);
}

logLabeledSuccess(
"hosting:channels",
Expand Down
15 changes: 15 additions & 0 deletions src/hosting/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ export async function addAuthDomain(project: string, url: string): Promise<strin
return await updateAuthDomains(project, authDomains);
}

/**
* Removes channel domain from Firebase Auth list.
* @param project the project ID.
* @param url the url of the channel.
*/
export async function removeAuthDomain(project: string, url: string): Promise<string[]> {
const domains = await getAuthDomains(project);
if (!domains.length) {
return domains;
}
const targetDomain = url.replace("https://", "");
const authDomains = domains.filter((domain: string) => domain != targetDomain);
return updateAuthDomains(project, authDomains);
}

/**
* Constructs a list of "clean domains"
* by including all existing auth domains
Expand Down

0 comments on commit c6ab336

Please sign in to comment.