diff --git a/src/Components/GoalModal/DeleteGoalModal.tsx b/src/Components/GoalModal/DeleteGoalModal.tsx index bd42a3f..4d592d4 100644 --- a/src/Components/GoalModal/DeleteGoalModal.tsx +++ b/src/Components/GoalModal/DeleteGoalModal.tsx @@ -24,6 +24,11 @@ export default function DeleteGoalModal({ goalId }: { goalId: string }) { }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; } diff --git a/src/Components/NameUpdate/NameUpdate.tsx b/src/Components/NameUpdate/NameUpdate.tsx index cfcecad..24d0b24 100644 --- a/src/Components/NameUpdate/NameUpdate.tsx +++ b/src/Components/NameUpdate/NameUpdate.tsx @@ -43,6 +43,11 @@ export default function NameUpdate() { }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; } diff --git a/src/Components/PostModal/DeletePostModal.tsx b/src/Components/PostModal/DeletePostModal.tsx index cd97248..e43f51c 100644 --- a/src/Components/PostModal/DeletePostModal.tsx +++ b/src/Components/PostModal/DeletePostModal.tsx @@ -30,6 +30,11 @@ export default function DeletePostModal({ }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; } diff --git a/src/utils/API/Goal/createGoal.ts b/src/utils/API/Goal/createGoal.ts index f755d19..a28696c 100644 --- a/src/utils/API/Goal/createGoal.ts +++ b/src/utils/API/Goal/createGoal.ts @@ -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"; @@ -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", @@ -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 = "不明なエラーが発生しました"; diff --git a/src/utils/API/Goal/updateGoal.ts b/src/utils/API/Goal/updateGoal.ts index b214bfb..33dc381 100644 --- a/src/utils/API/Goal/updateGoal.ts +++ b/src/utils/API/Goal/updateGoal.ts @@ -1,5 +1,4 @@ import { functionsEndpoint } from "@/app/firebase"; -import { showSnackBar } from "@/Components/SnackBar/SnackBar"; import getAppCheckToken from "@/utils/getAppCheckToken"; /** @@ -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", @@ -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 = "不明なエラーが発生しました"; diff --git a/src/utils/API/Post/createPost.ts b/src/utils/API/Post/createPost.ts index 0293422..cd21d96 100644 --- a/src/utils/API/Post/createPost.ts +++ b/src/utils/API/Post/createPost.ts @@ -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"; @@ -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", @@ -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 = "不明なエラーが発生しました"; diff --git a/src/utils/API/Reaction/updateReaction.ts b/src/utils/API/Reaction/updateReaction.ts index 2e897c5..4b4a7f9 100644 --- a/src/utils/API/Reaction/updateReaction.ts +++ b/src/utils/API/Reaction/updateReaction.ts @@ -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"; @@ -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", diff --git a/src/utils/API/Result/fetchResult.ts b/src/utils/API/Result/fetchResult.ts index 39b1525..d5cf61d 100644 --- a/src/utils/API/Result/fetchResult.ts +++ b/src/utils/API/Result/fetchResult.ts @@ -1,5 +1,4 @@ import { functionsEndpoint } from "@/app/firebase"; -import { showSnackBar } from "@/Components/SnackBar/SnackBar"; import getAppCheckToken from "@/utils/getAppCheckToken"; /** @@ -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()}`, @@ -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 = "不明なエラーが発生しました"; diff --git a/src/utils/API/User/fetchUser.ts b/src/utils/API/User/fetchUser.ts index ecea0b8..1d7cbdc 100644 --- a/src/utils/API/User/fetchUser.ts +++ b/src/utils/API/User/fetchUser.ts @@ -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"; @@ -10,17 +9,7 @@ import getAppCheckToken from "@/utils/getAppCheckToken"; * @return {*} {Promise} */ export const fetchUserById = async (userId: string): Promise => { - 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", @@ -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 = "不明なエラーが発生しました"; diff --git a/src/utils/Auth/signUpWithMail.tsx b/src/utils/Auth/signUpWithMail.tsx index 52e0a89..48a67c5 100644 --- a/src/utils/Auth/signUpWithMail.tsx +++ b/src/utils/Auth/signUpWithMail.tsx @@ -41,6 +41,11 @@ export const signUpWithMail = async ( }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; } diff --git a/src/utils/CloudMessaging/notificationController.ts b/src/utils/CloudMessaging/notificationController.ts index 6cf8e1a..7664d4f 100644 --- a/src/utils/CloudMessaging/notificationController.ts +++ b/src/utils/CloudMessaging/notificationController.ts @@ -50,6 +50,11 @@ export async function requestPermission(userId: string): Promise { }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; } @@ -102,6 +107,11 @@ export async function revokePermission(userId: string): Promise { }); if (!appCheckToken) { + showSnackBar({ + message: + "App Checkの初期化に失敗しました。debug tokenがサーバーに登録されていることを確認してください。", + type: "warning", + }); return; }