Skip to content

Commit 87434cc

Browse files
authored
Catch auth channel update on channel deletion (#3024)
* wrap and catch error if deleting domain fails * migrate gcp auth api to apiv2 * add changelog * fix a word
1 parent 79a3878 commit 87434cc

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Catches errors while updating authorized domains when deleting channels, printing a warning instead of failing.

src/commands/hosting-channel-delete.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { bold, underline } from "cli-color";
2+
import marked from "marked";
23

34
import { Command } from "../command";
5+
import { consoleUrl, logLabeledSuccess, logLabeledWarning } from "../utils";
46
import { deleteChannel, normalizeName, getChannel, removeAuthDomain } from "../hosting/api";
7+
import { promptOnce } from "../prompt";
8+
import { requireHostingSite } from "../requireHostingSite";
59
import { requirePermissions } from "../requirePermissions";
610
import * as getProjectId from "../getProjectId";
711
import * as requireConfig from "../requireConfig";
8-
import { logLabeledSuccess } from "../utils";
9-
import { promptOnce } from "../prompt";
10-
import { requireHostingSite } from "../requireHostingSite";
11-
12-
interface ChannelInfo {
13-
target: string | null;
14-
site: string;
15-
url: string;
16-
expireTime: string;
17-
}
12+
import logger from "../logger";
1813

1914
export default new Command("hosting:channel:delete <channelId>")
2015
.description("delete a Firebase Hosting channel")
@@ -51,7 +46,20 @@ export default new Command("hosting:channel:delete <channelId>")
5146

5247
await deleteChannel(projectId, siteId, channelId);
5348
if (channel) {
54-
await removeAuthDomain(projectId, channel.url);
49+
try {
50+
await removeAuthDomain(projectId, channel.url);
51+
} catch (e) {
52+
logLabeledWarning(
53+
"hosting:channel",
54+
marked(
55+
`Unable to remove channel domain from Firebase Auth. Visit the Firebase Console at ${consoleUrl(
56+
projectId,
57+
"/authentication/providers"
58+
)}`
59+
)
60+
);
61+
logger.debug("[hosting] unable to remove auth domain", e);
62+
}
5563
}
5664

5765
logLabeledSuccess(

src/gcp/auth.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
import * as api from "../api";
1+
import { Client } from "../apiv2";
2+
import { identityOrigin } from "../api";
23

4+
const apiClient = new Client({ urlPrefix: identityOrigin, auth: true });
5+
6+
/**
7+
* Returns the list of authorized domains.
8+
* @param project project identifier.
9+
* @return authorized domains.
10+
*/
311
export async function getAuthDomains(project: string): Promise<string[]> {
4-
const res = await api.request("GET", `/admin/v2/projects/${project}/config`, {
5-
auth: true,
6-
origin: api.identityOrigin,
7-
});
8-
return res?.body?.authorizedDomains;
12+
const res = await apiClient.get<{ authorizedDomains: string[] }>(
13+
`/admin/v2/projects/${project}/config`
14+
);
15+
return res.body.authorizedDomains;
916
}
1017

18+
/**
19+
* Updates the list of authorized domains.
20+
* @param project project identifier.
21+
* @param authDomains full list of authorized domains.
22+
* @return authorized domains.
23+
*/
1124
export async function updateAuthDomains(project: string, authDomains: string[]): Promise<string[]> {
12-
const resp = await api.request(
13-
"PATCH",
14-
`/admin/v2/projects/${project}/config?update_mask=authorizedDomains`,
15-
{
16-
auth: true,
17-
origin: api.identityOrigin,
18-
data: {
19-
authorizedDomains: authDomains,
20-
},
21-
}
25+
const res = await apiClient.patch<
26+
{ authorizedDomains: string[] },
27+
{ authorizedDomains: string[] }
28+
>(
29+
`/admin/v2/projects/${project}/config`,
30+
{ authorizedDomains: authDomains },
31+
{ queryParams: { update_mask: "authorizedDomains" } }
2232
);
23-
return resp?.body?.authorizedDomains;
33+
return res.body.authorizedDomains;
2434
}

0 commit comments

Comments
 (0)