Skip to content

Commit

Permalink
fixup! App CheckのtokenをAPI使用時に取得するように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Jan 28, 2025
1 parent 079b6a2 commit 7adec57
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 72 deletions.
5 changes: 5 additions & 0 deletions src/Components/GoalModal/DeleteGoalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export default function DeleteGoalModal({ goalId }: { goalId: string }) {
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Components/NameUpdate/NameUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default function NameUpdate() {
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Components/PostModal/DeletePostModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export default function DeletePostModal({
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down
17 changes: 5 additions & 12 deletions src/utils/API/Goal/createGoal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import { Goal } from "@/types/types";
import getAppCheckToken from "@/utils/getAppCheckToken";

Expand All @@ -20,17 +19,7 @@ export const createGoal = async (postData: Goal) => {
throw new Error("too long comment");
}

const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
return;
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(`${functionsEndpoint}/goal/`, {
method: "POST",
Expand Down Expand Up @@ -75,6 +64,10 @@ export const handleCreateGoalError = (error: unknown) => {
if (error.message.includes("500")) {
snackBarMessage = "サーバーエラーが発生しました";
}
if (error.message.includes("App Checkの初期化に失敗しました。")) {
snackBarMessage =
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。";
}
} else {
console.error("An unknown error occurred");
snackBarMessage = "不明なエラーが発生しました";
Expand Down
17 changes: 5 additions & 12 deletions src/utils/API/Goal/updateGoal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import getAppCheckToken from "@/utils/getAppCheckToken";

/**
Expand Down Expand Up @@ -29,17 +28,7 @@ export const updateGoal = async (
throw new Error("too long comment");
}

const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
return;
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(`${functionsEndpoint}/goal/${goalId}`, {
method: "PUT",
Expand Down Expand Up @@ -84,6 +73,10 @@ export const handleUpdateGoalError = (error: unknown) => {
if (error.message.includes("500")) {
snackBarMessage = "サーバーエラーが発生しました";
}
if (error.message.includes("App Checkの初期化に失敗しました。")) {
snackBarMessage =
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。";
}
} else {
console.error("An unknown error occurred");
snackBarMessage = "不明なエラーが発生しました";
Expand Down
17 changes: 5 additions & 12 deletions src/utils/API/Post/createPost.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import { PostWithGoalId } from "@/types/types";
import getAppCheckToken from "@/utils/getAppCheckToken";

Expand All @@ -15,17 +14,7 @@ export const createPost = async (postData: PostWithGoalId) => {
throw new Error("too long comment");
}

const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
return;
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(`${functionsEndpoint}/post/`, {
method: "POST",
Expand Down Expand Up @@ -67,6 +56,10 @@ export const handleCreatePostError = (error: unknown) => {
if (error.message.includes("500")) {
snackBarMessage = "サーバーエラーが発生しました";
}
if (error.message.includes("App Checkの初期化に失敗しました。")) {
snackBarMessage =
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。";
}
} else {
console.error("An unknown error occurred");
snackBarMessage = "不明なエラーが発生しました";
Expand Down
13 changes: 1 addition & 12 deletions src/utils/API/Reaction/updateReaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import { ReactionTypeMap } from "@/types/types";
import getAppCheckToken from "@/utils/getAppCheckToken";

Expand All @@ -17,17 +16,7 @@ export const updateReaction = async (
goalId: string,
reactionType: ReactionTypeMap | ""
) => {
const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
return;
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(`${functionsEndpoint}/reaction/${goalId}`, {
method: "PUT",
Expand Down
17 changes: 5 additions & 12 deletions src/utils/API/Result/fetchResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import getAppCheckToken from "@/utils/getAppCheckToken";

/**
Expand Down Expand Up @@ -36,17 +35,7 @@ export const fetchResult = async ({
queryParams.append("limit", limit.toString());
}

const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
return;
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(
`${functionsEndpoint}/result/${userId}?${queryParams.toString()}`,
Expand Down Expand Up @@ -89,6 +78,10 @@ export const handleFetchResultError = (error: unknown) => {
if (error.message.includes("500")) {
snackBarMessage = "サーバーエラーが発生しました";
}
if (error.message.includes("App Checkの初期化に失敗しました。")) {
snackBarMessage =
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。";
}
} else {
console.error("An unknown error occurred");
snackBarMessage = "不明なエラーが発生しました";
Expand Down
17 changes: 5 additions & 12 deletions src/utils/API/User/fetchUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { functionsEndpoint } from "@/app/firebase";
import { showSnackBar } from "@/Components/SnackBar/SnackBar";
import { User } from "@/types/types";
import getAppCheckToken from "@/utils/getAppCheckToken";

Expand All @@ -10,17 +9,7 @@ import getAppCheckToken from "@/utils/getAppCheckToken";
* @return {*} {Promise<User>}
*/
export const fetchUserById = async (userId: string): Promise<User> => {
const appCheckToken = await getAppCheckToken().catch((error) => {
showSnackBar({
message: error.message,
type: "warning",
});
return "";
});

if (!appCheckToken) {
throw new Error("Failed to get App Check token");
}
const appCheckToken = await getAppCheckToken();

const response = await fetch(`${functionsEndpoint}/user/id/${userId}`, {
method: "GET",
Expand Down Expand Up @@ -59,6 +48,10 @@ export const handleFetchUserError = (error: unknown) => {
if (error.message.includes("429")) {
snackBarMessage = "リクエストが多すぎます。数分後に再度お試しください。";
}
if (error.message.includes("App Checkの初期化に失敗しました。")) {
snackBarMessage =
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。";
}
} else {
console.error("An unknown error occurred");
snackBarMessage = "不明なエラーが発生しました";
Expand Down
5 changes: 5 additions & 0 deletions src/utils/Auth/signUpWithMail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const signUpWithMail = async (
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils/CloudMessaging/notificationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export async function requestPermission(userId: string): Promise<void> {
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down Expand Up @@ -102,6 +107,11 @@ export async function revokePermission(userId: string): Promise<void> {
});

if (!appCheckToken) {
showSnackBar({
message:
"App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。",
type: "warning",
});
return;
}

Expand Down

0 comments on commit 7adec57

Please sign in to comment.