Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix#447 Sentryで利用者のユーザーIDを収集する #455

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 44 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/common_components/auth/signin/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 "サインインできませんでした";
},
Expand Down
4 changes: 3 additions & 1 deletion src/common_components/auth/signup/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -48,9 +49,10 @@ export const SignupForm: React.FC<SignupFormProps> = ({ 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: "ユーザ登録に失敗しました" });
Expand Down
2 changes: 2 additions & 0 deletions src/common_components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -121,6 +122,7 @@ export const Header: FC = () => {
toast.promise(
(async (): Promise<void> => {
await signOut(auth);
Sentry.setUser(null);
})(),
{
loading: "サインアウトしています",
Expand Down