From 9ffada82616e2c374d046f003a69b39799496dce Mon Sep 17 00:00:00 2001 From: naohanpen Date: Sun, 13 Oct 2024 13:01:17 +0900 Subject: [PATCH] =?UTF-8?q?fix#447=20Sentry=E3=81=A7=E5=88=A9=E7=94=A8?= =?UTF-8?q?=E8=80=85=E3=81=AE=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BCID?= =?UTF-8?q?=E3=82=92=E5=8F=8E=E9=9B=86=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 89 +++++++++---------- .../auth/signin/SignInPage.tsx | 10 ++- .../auth/signup/SignupForm.tsx | 4 +- src/common_components/header/Header.tsx | 2 + 4 files changed, 57 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7203edcb..4df8e21e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2091,7 +2091,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "dev": true, "inBundle": true, "license": "MIT", "engines": { @@ -5479,33 +5478,6 @@ "integrity": "sha512-S3Kq8e7LqxkA9s7HKLqXGTGck1uwis5vAXan3FnU5yw1Ec5hsSGnq4s/UCaSqABPOnOTg7zASLyst7+ohgWexg==", "dev": true }, - "node_modules/@sentry-internal/feedback": { - "version": "7.111.0", - "resolved": "https://registry.npmjs.org/@sentry-internal/feedback/-/feedback-7.111.0.tgz", - "integrity": "sha512-xaKgPPDEirOan7c9HwzYA1KK87kRp/qfIx9ZKLOEtxwy6nqoMuSByGqSwm1Oqfcjpbd7y6/y+7Bw+69ZKNVLDQ==", - "dependencies": { - "@sentry/core": "7.111.0", - "@sentry/types": "7.111.0", - "@sentry/utils": "7.111.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@sentry-internal/replay-canvas": { - "version": "7.111.0", - "resolved": "https://registry.npmjs.org/@sentry-internal/replay-canvas/-/replay-canvas-7.111.0.tgz", - "integrity": "sha512-3KPBIpiegTYmuVw9gA2aKuliAQONS3Ny1kJc9x5kz6XQGuLFxqlh6KzoCVaKfQJeq2WJqRNeR4KFFuNGuB3H8w==", - "dependencies": { - "@sentry/core": "7.111.0", - "@sentry/replay": "7.111.0", - "@sentry/types": "7.111.0", - "@sentry/utils": "7.111.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/@sentry-internal/tracing": { "version": "7.111.0", "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.111.0.tgz", @@ -5519,23 +5491,6 @@ "node": ">=8" } }, - "node_modules/@sentry/browser": { - "version": "7.111.0", - "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.111.0.tgz", - "integrity": "sha512-x7S9XoJh+TbMnur4eBhPpCVo+p7udABBV2gQk+Iw6LP9e8EFKmGmNyl76vSsT6GeFJ7mwxDEKfuwbVoLBjIvHw==", - "dependencies": { - "@sentry-internal/feedback": "7.111.0", - "@sentry-internal/replay-canvas": "7.111.0", - "@sentry-internal/tracing": "7.111.0", - "@sentry/core": "7.111.0", - "@sentry/replay": "7.111.0", - "@sentry/types": "7.111.0", - "@sentry/utils": "7.111.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@sentry/cli": { "version": "1.77.3", "resolved": "https://registry.npmjs.org/@sentry/cli/-/cli-1.77.3.tgz", @@ -5670,6 +5625,50 @@ "react": "15.x || 16.x || 17.x || 18.x" } }, + "node_modules/@sentry/react/node_modules/@sentry-internal/feedback": { + "version": "7.111.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/feedback/-/feedback-7.111.0.tgz", + "integrity": "sha512-xaKgPPDEirOan7c9HwzYA1KK87kRp/qfIx9ZKLOEtxwy6nqoMuSByGqSwm1Oqfcjpbd7y6/y+7Bw+69ZKNVLDQ==", + "dependencies": { + "@sentry/core": "7.111.0", + "@sentry/types": "7.111.0", + "@sentry/utils": "7.111.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@sentry/react/node_modules/@sentry-internal/replay-canvas": { + "version": "7.111.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/replay-canvas/-/replay-canvas-7.111.0.tgz", + "integrity": "sha512-3KPBIpiegTYmuVw9gA2aKuliAQONS3Ny1kJc9x5kz6XQGuLFxqlh6KzoCVaKfQJeq2WJqRNeR4KFFuNGuB3H8w==", + "dependencies": { + "@sentry/core": "7.111.0", + "@sentry/replay": "7.111.0", + "@sentry/types": "7.111.0", + "@sentry/utils": "7.111.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@sentry/react/node_modules/@sentry/browser": { + "version": "7.111.0", + "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.111.0.tgz", + "integrity": "sha512-x7S9XoJh+TbMnur4eBhPpCVo+p7udABBV2gQk+Iw6LP9e8EFKmGmNyl76vSsT6GeFJ7mwxDEKfuwbVoLBjIvHw==", + "dependencies": { + "@sentry-internal/feedback": "7.111.0", + "@sentry-internal/replay-canvas": "7.111.0", + "@sentry-internal/tracing": "7.111.0", + "@sentry/core": "7.111.0", + "@sentry/replay": "7.111.0", + "@sentry/types": "7.111.0", + "@sentry/utils": "7.111.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@sentry/replay": { "version": "7.111.0", "resolved": "https://registry.npmjs.org/@sentry/replay/-/replay-7.111.0.tgz", diff --git a/src/common_components/auth/signin/SignInPage.tsx b/src/common_components/auth/signin/SignInPage.tsx index f6751800..acd0af38 100644 --- a/src/common_components/auth/signin/SignInPage.tsx +++ b/src/common_components/auth/signin/SignInPage.tsx @@ -1,6 +1,7 @@ "use client"; import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; +import * as Sentry from "@sentry/nextjs"; import { useForm } from "react-hook-form"; import toast from "react-hot-toast"; import { css, cx } from "@styled-system/css"; @@ -28,13 +29,18 @@ export const SigninForm: React.FC = () => { const auth = getAuth(); toast.promise( (async () => { - await signInWithEmailAndPassword(auth, data.email, data.password); + const { user } = await signInWithEmailAndPassword(auth, data.email, data.password); + Sentry.setUser({ id: user.uid }); reset(); })(), { loading: "サインインしています", success: "サインインしました", - error: () => { + error: (error) => { + Sentry.captureMessage( + `Failed to sign in: ${error.code}`, + error.code === "auth/invalid-credential" ? "log" : "info", + ); setError("root", { message: "サインインできませんでした" }); return "サインインできませんでした"; }, diff --git a/src/common_components/auth/signup/SignupForm.tsx b/src/common_components/auth/signup/SignupForm.tsx index 06c8351b..c86ce22e 100644 --- a/src/common_components/auth/signup/SignupForm.tsx +++ b/src/common_components/auth/signup/SignupForm.tsx @@ -9,6 +9,7 @@ import { getAuth, sendEmailVerification, signInWithEmailAndPassword } from "fire import { SignupSchema, SignupSchemaType } from "@/lib/valibot"; import { valibotResolver } from "@hookform/resolvers/valibot"; import { Dispatch, SetStateAction } from "react"; +import * as Sentry from "@sentry/nextjs"; let labelAndInputStyle = css({ display: "flex", @@ -48,9 +49,10 @@ export const SignupForm: React.FC = ({ setUserEmail }) => { }).then((res) => { if (res.status === 201) { const auth = getAuth(); - signInWithEmailAndPassword(auth, data.email, data.password).then(() => { + signInWithEmailAndPassword(auth, data.email, data.password).then(({ user }) => { setUserEmail(data.email); sendEmailVerification(auth.currentUser!); + Sentry.setUser({ id: user.uid }); }); } else { setError("root", { message: "ユーザ登録に失敗しました" }); diff --git a/src/common_components/header/Header.tsx b/src/common_components/header/Header.tsx index f495f413..4385594d 100644 --- a/src/common_components/header/Header.tsx +++ b/src/common_components/header/Header.tsx @@ -3,6 +3,7 @@ import { useAuthState } from "@/lib/firebase"; import { css } from "@styled-system/css"; import { getAuth, signOut } from "firebase/auth"; +import * as Sentry from "@sentry/nextjs"; import { FC } from "react"; import toast from "react-hot-toast"; import Image from "next/image"; @@ -121,6 +122,7 @@ export const Header: FC = () => { toast.promise( (async (): Promise => { await signOut(auth); + Sentry.setUser(null); })(), { loading: "サインアウトしています",