From f6604bb7f27d02c728af3a490f281f4fea0dfab0 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Tue, 10 Dec 2024 14:04:36 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E8=AA=8D=E8=A8=BC=E9=96=A2=E9=80=A3?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D=E3=81=A8?= =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4,=20?= =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/UserForm/UserForm.tsx | 106 ------------------ src/app/account/page.tsx | 12 +- .../API/{createUserAPI.ts => createUser.ts} | 2 +- .../{loginUserAuth.ts => signInWithMail.ts} | 2 +- ...eAccount.ts => signUpWithGoogleAccount.ts} | 9 +- .../{createUserAuth.ts => signUpWithMail.ts} | 10 +- 6 files changed, 18 insertions(+), 123 deletions(-) delete mode 100644 src/Components/UserForm/UserForm.tsx rename src/utils/API/{createUserAPI.ts => createUser.ts} (90%) rename src/utils/Auth/{loginUserAuth.ts => signInWithMail.ts} (89%) rename src/utils/Auth/{signInWithGoogleAccount.ts => signUpWithGoogleAccount.ts} (80%) rename src/utils/Auth/{createUserAuth.ts => signUpWithMail.ts} (84%) diff --git a/src/Components/UserForm/UserForm.tsx b/src/Components/UserForm/UserForm.tsx deleted file mode 100644 index 0b21666..0000000 --- a/src/Components/UserForm/UserForm.tsx +++ /dev/null @@ -1,106 +0,0 @@ -"use client"; -import { auth } from "@/app/firebase"; -import { createUser } from "@/utils/Auth/createUserAuth"; -import { loginUser } from "@/utils/Auth/loginUserAuth"; -import { signInAsGuest } from "@/utils/Auth/signInAnonymously"; -import { signInWithGoogleAccount } from "@/utils/Auth/signInWithGoogleAccount"; -import { useUser } from "@/utils/UserContext"; -import { signOut } from "firebase/auth"; -import React, { useState } from "react"; - -export default function UserForm() { - const [name, setName] = useState(""); - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - - const { user } = useUser(); - - const handleRegisterSubmit = async (event: React.FormEvent) => { - event.preventDefault(); - await createUser(email, password, name); - }; - - const handleLoginSubmit = async (event: React.FormEvent) => { - event.preventDefault(); - await loginUser(email, password); - }; - - const handleGoogleLogin = async () => { - await signInWithGoogleAccount(); - }; - - const handleGuestLogin = async () => { - await signInAsGuest(); - }; - - const handleLogout = async () => { - try { - await signOut(auth); - console.log("Signed out"); - } catch (error) { - console.error("errorCode:", (error as Error)?.name); - console.error("errorMessage:", (error as Error)?.message); - } - }; - - return ( - <> -

{user ? `ログイン中: ${user.name}` : "ログインしてください"}

- アカウント作成 -
- - -
- ログイン -
- - -
- - - - - ); -} diff --git a/src/app/account/page.tsx b/src/app/account/page.tsx index 9ff0d8d..4f2fbbe 100644 --- a/src/app/account/page.tsx +++ b/src/app/account/page.tsx @@ -2,10 +2,10 @@ import { auth } from "@/app/firebase"; import NameUpdate from "@/Components/NameUpdate/NameUpdate"; import Notification from "@/Components/Notification/Notification"; -import { createUser } from "@/utils/Auth/createUserAuth"; -import { loginUser } from "@/utils/Auth/loginUserAuth"; import { signInAsGuest } from "@/utils/Auth/signInAnonymously"; -import { signInWithGoogleAccount } from "@/utils/Auth/signInWithGoogleAccount"; +import { signInWithMail } from "@/utils/Auth/signInWithMail"; +import { signUpWithGoogleAccount } from "@/utils/Auth/signUpWithGoogleAccount"; +import { signUpWithMail } from "@/utils/Auth/signUpWithMail"; import { useUser } from "@/utils/UserContext"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; @@ -59,16 +59,16 @@ export default function Account() { const handleRegisterSubmit = async (event: React.FormEvent) => { event.preventDefault(); - await createUser(email, password, name); + await signUpWithMail(email, password, name); }; const handleLoginSubmit = async (event: React.FormEvent) => { event.preventDefault(); - await loginUser(email, password); + await signInWithMail(email, password); }; const handleGoogleLogin = async () => { - await signInWithGoogleAccount(); + await signUpWithGoogleAccount(); }; const handleGuestLogin = async () => { diff --git a/src/utils/API/createUserAPI.ts b/src/utils/API/createUser.ts similarity index 90% rename from src/utils/API/createUserAPI.ts rename to src/utils/API/createUser.ts index 80e1d1c..66acbb5 100644 --- a/src/utils/API/createUserAPI.ts +++ b/src/utils/API/createUser.ts @@ -7,7 +7,7 @@ import { appCheckToken, functionsEndpoint } from "@/app/firebase"; * @param {string} name * @param {string} uid */ -export const createUserAPI = async (name: string, uid: string) => { +export const createUser = async (name: string, uid: string) => { const response = await fetch(`${functionsEndpoint}/user/`, { method: "POST", headers: { diff --git a/src/utils/Auth/loginUserAuth.ts b/src/utils/Auth/signInWithMail.ts similarity index 89% rename from src/utils/Auth/loginUserAuth.ts rename to src/utils/Auth/signInWithMail.ts index 4ceadac..6177a29 100644 --- a/src/utils/Auth/loginUserAuth.ts +++ b/src/utils/Auth/signInWithMail.ts @@ -8,7 +8,7 @@ import { signInWithEmailAndPassword } from "firebase/auth"; * @param {string} password * @return {*} */ -export const loginUser = (email: string, password: string) => { +export const signInWithMail = (email: string, password: string) => { signInWithEmailAndPassword(auth, email, password) .then(async (userCredential) => { // Signed in diff --git a/src/utils/Auth/signInWithGoogleAccount.ts b/src/utils/Auth/signUpWithGoogleAccount.ts similarity index 80% rename from src/utils/Auth/signInWithGoogleAccount.ts rename to src/utils/Auth/signUpWithGoogleAccount.ts index 4ba8738..b2dcb00 100644 --- a/src/utils/Auth/signInWithGoogleAccount.ts +++ b/src/utils/Auth/signUpWithGoogleAccount.ts @@ -1,5 +1,5 @@ import { auth, googleProvider } from "@/app/firebase"; -import { createUserAPI } from "@/utils/API/createUserAPI"; +import { createUser } from "@/utils/API/createUser"; import { updateUser } from "@/utils/UserContext"; import { getAdditionalUserInfo, signInWithPopup } from "firebase/auth"; @@ -7,17 +7,14 @@ import { getAdditionalUserInfo, signInWithPopup } from "firebase/auth"; * Googleアカウントでログインする * */ -export const signInWithGoogleAccount = async () => { +export const signUpWithGoogleAccount = async () => { try { const result = await signInWithPopup(auth, googleProvider); // 初めての時だけユーザー情報を登録する if (getAdditionalUserInfo(result)?.isNewUser) { // uidとdocument IDを一致させる - await createUserAPI( - result.user.displayName ?? "no name", - result.user.uid - ); + await createUser(result.user.displayName ?? "no name", result.user.uid); updateUser({ uid: result.user.uid, name: result.user.displayName ?? "no name", diff --git a/src/utils/Auth/createUserAuth.ts b/src/utils/Auth/signUpWithMail.ts similarity index 84% rename from src/utils/Auth/createUserAuth.ts rename to src/utils/Auth/signUpWithMail.ts index c2782e9..fe8fe09 100644 --- a/src/utils/Auth/createUserAuth.ts +++ b/src/utils/Auth/signUpWithMail.ts @@ -1,5 +1,5 @@ import { auth } from "@/app/firebase"; -import { createUserAPI } from "@/utils/API/createUserAPI"; +import { createUser } from "@/utils/API/createUser"; import { updateUser } from "@/utils/UserContext"; import { createUserWithEmailAndPassword } from "firebase/auth"; @@ -10,7 +10,11 @@ import { createUserWithEmailAndPassword } from "firebase/auth"; * @param {string} password * @param {string} name */ -export const createUser = (email: string, password: string, name: string) => { +export const signUpWithMail = ( + email: string, + password: string, + name: string +) => { // メールは初回ログインの時のみ成功する、2回目以降はエラーになるので、ログインを使う createUserWithEmailAndPassword(auth, email, password) .then(async (userCredential) => { @@ -18,7 +22,7 @@ export const createUser = (email: string, password: string, name: string) => { const user = userCredential.user; // uidとdocument IDを一致させる - await createUserAPI(name, user.uid); + await createUser(name, user.uid); updateUser({ uid: user.uid, name: name, From 81426e9defe55a8a767339e68bdac35c4424b084 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Tue, 10 Dec 2024 15:04:53 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E3=82=A2?= =?UTF-8?q?=E3=83=89=E3=83=AC=E3=82=B9=E3=81=AE=E8=AA=8D=E8=A8=BC=E6=83=85?= =?UTF-8?q?=E5=A0=B1=E3=81=AB=E9=96=A2=E3=81=99=E3=82=8B=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=82=92UserData=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/NameUpdate/NameUpdate.tsx | 15 +++++++++++++++ src/app/account/page.tsx | 7 +++++++ src/types/types.ts | 1 + src/utils/Auth/signUpWithGoogleAccount.ts | 1 + src/utils/Auth/signUpWithMail.ts | 14 +++++++++++++- src/utils/UserContext.tsx | 7 ++++++- 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Components/NameUpdate/NameUpdate.tsx b/src/Components/NameUpdate/NameUpdate.tsx index 99848c6..47a2219 100644 --- a/src/Components/NameUpdate/NameUpdate.tsx +++ b/src/Components/NameUpdate/NameUpdate.tsx @@ -39,6 +39,21 @@ export default function NameUpdate({ setOpen(false); } }; + + // 以下のJoy UIによるエラーを無効化 + // Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release. Error Component Stack + try { + const consoleError = console.error; + console.error = (...args) => { + if (args[0]?.includes("Accessing element.ref was removed")) { + return; + } + consoleError(...args); + }; + } catch { + console.error("Failed to disable Joy UI error"); + } + return ( setOpen(false)} keepMounted disablePortal> ログイン中: {user.name} {user.loginType !== "Guest" && } + {!user.isMailVerified && ( + + メールに届いた認証リンクを確認してください。 +
+ 認証が完了するまで閲覧以外の機能は制限されます。 +
+ )} ログアウト diff --git a/src/types/types.ts b/src/types/types.ts index a2b7f7b..f79bb22 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -3,6 +3,7 @@ export interface UserData { name: string; streak: number; loginType: LoginType; + isMailVerified: boolean; } export type LoginType = "Mail" | "Google" | "Guest" | "None"; diff --git a/src/utils/Auth/signUpWithGoogleAccount.ts b/src/utils/Auth/signUpWithGoogleAccount.ts index b2dcb00..707597c 100644 --- a/src/utils/Auth/signUpWithGoogleAccount.ts +++ b/src/utils/Auth/signUpWithGoogleAccount.ts @@ -20,6 +20,7 @@ export const signUpWithGoogleAccount = async () => { name: result.user.displayName ?? "no name", streak: 0, loginType: "Google", + isMailVerified: result.user.emailVerified, }); } diff --git a/src/utils/Auth/signUpWithMail.ts b/src/utils/Auth/signUpWithMail.ts index fe8fe09..bd9ef2f 100644 --- a/src/utils/Auth/signUpWithMail.ts +++ b/src/utils/Auth/signUpWithMail.ts @@ -1,7 +1,10 @@ import { auth } from "@/app/firebase"; import { createUser } from "@/utils/API/createUser"; import { updateUser } from "@/utils/UserContext"; -import { createUserWithEmailAndPassword } from "firebase/auth"; +import { + createUserWithEmailAndPassword, + sendEmailVerification, +} from "firebase/auth"; /** * Firebase Authenticationでユーザーを作成し、生成されたuidをドキュメントIDとしてFirestoreにユーザー情報を登録する @@ -28,7 +31,16 @@ export const signUpWithMail = ( name: name, streak: 0, loginType: "Mail", + isMailVerified: user.emailVerified, }); + + // メール確認リンクを送信 + try { + await sendEmailVerification(user); + console.log("確認メールを送信しました。"); + } catch (verificationError) { + console.error("確認メールの送信に失敗しました:", verificationError); + } console.log(user); }) .catch((error) => { diff --git a/src/utils/UserContext.tsx b/src/utils/UserContext.tsx index 5b915d7..45e5ab4 100644 --- a/src/utils/UserContext.tsx +++ b/src/utils/UserContext.tsx @@ -79,6 +79,7 @@ export const UserProvider = ({ children }: Props) => { name: "Guest", streak: 0, loginType: "Guest", + isMailVerified: true, }; setUser(guestData); return; @@ -89,7 +90,11 @@ export const UserProvider = ({ children }: Props) => { // ユーザーデータを作成する前にfetchしようとして"User not found"になるので、postした場所でsetさせている // "User not found"ではない(= 初回ログイン直後ではない)場合のみsetする if (userData.uid) { - setUser({ ...userData, loginType }); + setUser({ + ...userData, + loginType, + isMailVerified: firebaseUser.emailVerified, + }); } } catch (error) { console.error("ユーザーデータの取得に失敗しました:", error); From 35338e6826aec1c7ec771f553f6bfcf5ed90c297 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Tue, 10 Dec 2024 15:18:49 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E8=AA=8D?= =?UTF-8?q?=E8=A8=BC=E3=81=8C=E6=9C=AA=E5=AE=8C=E4=BA=86=E3=81=AE=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AF=E4=B8=80=E9=83=A8=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E5=88=B6=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/GoalModal/GoalModal.tsx | 8 +- src/Components/PostModal/PostModal.tsx | 2 - src/app/account/page.tsx | 187 ++++++++++++++----------- 3 files changed, 112 insertions(+), 85 deletions(-) diff --git a/src/Components/GoalModal/GoalModal.tsx b/src/Components/GoalModal/GoalModal.tsx index 9f0de99..2f2eadf 100644 --- a/src/Components/GoalModal/GoalModal.tsx +++ b/src/Components/GoalModal/GoalModal.tsx @@ -80,7 +80,7 @@ export default function GoalModal() { color="primary" startDecorator={} onClick={() => setOpen(true)} - disabled={!user || user?.loginType === "Guest"} + disabled={!user || user?.loginType === "Guest" || !user?.isMailVerified} > Create Goal @@ -124,7 +124,11 @@ export default function GoalModal() { type="submit" variant="solid" color="primary" - disabled={!user || user?.loginType === "Guest"} + disabled={ + !user || + user?.loginType === "Guest" || + !user?.isMailVerified + } endDecorator={} > Create Goal diff --git a/src/Components/PostModal/PostModal.tsx b/src/Components/PostModal/PostModal.tsx index 5d5b661..11fc9a8 100644 --- a/src/Components/PostModal/PostModal.tsx +++ b/src/Components/PostModal/PostModal.tsx @@ -131,7 +131,6 @@ export default function PostModal({ goalId }: { goalId: string }) { color="primary" startDecorator={} onClick={() => setOpen(true)} - disabled={!user || user?.loginType === "Guest"} > 写真を撮って完了する @@ -188,7 +187,6 @@ export default function PostModal({ goalId }: { goalId: string }) { type="submit" variant="solid" color="primary" - disabled={!user || user?.loginType === "Guest"} endDecorator={} onClick={handleUpload} > diff --git a/src/app/account/page.tsx b/src/app/account/page.tsx index 22b3242..726b2b2 100644 --- a/src/app/account/page.tsx +++ b/src/app/account/page.tsx @@ -124,7 +124,11 @@ export default function Account() { {user ? ( <> ログイン中: {user.name} + + {/* ゲストの場合は通知機能を利用しない */} {user.loginType !== "Guest" && } + + {/* メール認証が完了していない場合に表示 */} {!user.isMailVerified && ( メールに届いた認証リンクを確認してください。 @@ -132,10 +136,13 @@ export default function Account() { 認証が完了するまで閲覧以外の機能は制限されます。 )} + ログアウト - {user?.loginType !== "Guest" && ( + + {/* ゲストの場合は名前を変更しない */} + {user.loginType !== "Guest" && ( <> )} - ) : formMode === "register" ? ( - <> - 新規登録 -
- - setName(e.target.value)} - fullWidth - required - /> - setEmail(e.target.value)} - fullWidth - required - /> - setPassword(e.target.value)} - fullWidth - required - /> - - アカウント作成 - - -
- ) : ( <> - ログイン -
- + 新規登録 + + + setName(e.target.value)} + fullWidth + required + /> + setEmail(e.target.value)} + fullWidth + required + /> + setPassword(e.target.value)} + fullWidth + required + /> + + アカウント作成 + + + + + ) : ( + <> + ログイン +
+ + setEmail(e.target.value)} + fullWidth + required + /> + setPassword(e.target.value)} + fullWidth + required + /> + + ログイン + + +
+ + )} + <> + または + - setEmail(e.target.value)} - fullWidth - required - /> - setPassword(e.target.value)} - fullWidth - required - /> - - ログイン - -
- - - )} - {!user && ( - <> - または - - Googleでログイン - - - ゲストログイン - + Googleでログイン +
+ + ゲストログイン + + )} From e6eee37519a8ea51cb03156f5337330645fe65f2 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Tue, 10 Dec 2024 15:29:32 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E8=87=AA=E5=88=86=E3=81=AE=E7=9B=AE?= =?UTF-8?q?=E6=A8=99=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AE=E3=81=BF=E6=8A=95?= =?UTF-8?q?=E7=A8=BF=E3=81=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/Progress/Progress.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Components/Progress/Progress.tsx b/src/Components/Progress/Progress.tsx index acf29c5..a9f9b4b 100644 --- a/src/Components/Progress/Progress.tsx +++ b/src/Components/Progress/Progress.tsx @@ -1,6 +1,7 @@ -import { GoalWithId, SuccessResult } from "@/types/types"; +import { GoalWithId, SuccessResult, UserData } from "@/types/types"; import { fetchUserById } from "@/utils/API/fetchUser"; import { formatStringToDate } from "@/utils/DateFormatter"; +import { useUser } from "@/utils/UserContext"; import AppRegistrationRoundedIcon from "@mui/icons-material/AppRegistrationRounded"; import CheckRoundedIcon from "@mui/icons-material/CheckRounded"; import CloseIcon from "@mui/icons-material/Close"; @@ -46,6 +47,7 @@ export default function Progress({ pendingResults = [], }: ProgressProps) { const [userNames, setUserNames] = useState>({}); // + const { user } = useUser(); const fetchUserName = async (userId: string) => { if (userNames[userId]) return; // 既に取得済みの場合はキャッシュのように再利用 @@ -90,7 +92,7 @@ export default function Progress({ if (result.type === "failed") return failedStep(result as GoalWithId, userName); if (result.type === "pending") - return pendingStep(result as GoalWithId, userName); + return pendingStep(result as GoalWithId, userName, user as UserData); return null; })} @@ -173,7 +175,7 @@ const failedStep = (result: GoalWithId, userName: string) => { ); }; -const pendingStep = (result: GoalWithId, userName: string) => { +const pendingStep = (result: GoalWithId, userName: string, user: UserData) => { return ( { goalText={result.text} resultType="pending" /> - + {/* 自分の作成した目標の場合のみ投稿可能にする */} + {result.userId === user?.uid && } ); From c2972c19a91aaf486a4a6c5c440b0a73656ad033 Mon Sep 17 00:00:00 2001 From: MurakawaTakuya Date: Tue, 10 Dec 2024 15:42:46 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E3=82=A2?= =?UTF-8?q?=E3=83=89=E3=83=AC=E3=82=B9=E3=81=A7=E7=99=BB=E9=8C=B2=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AEdisplayName=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/NameUpdate/NameUpdate.tsx | 13 ++++++++++++- src/utils/Auth/signUpWithMail.ts | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Components/NameUpdate/NameUpdate.tsx b/src/Components/NameUpdate/NameUpdate.tsx index 47a2219..a916584 100644 --- a/src/Components/NameUpdate/NameUpdate.tsx +++ b/src/Components/NameUpdate/NameUpdate.tsx @@ -1,5 +1,5 @@ "use client"; -import { appCheckToken, functionsEndpoint } from "@/app/firebase"; +import { appCheckToken, auth, functionsEndpoint } from "@/app/firebase"; import { useUser } from "@/utils/UserContext"; import { DialogContent, @@ -10,6 +10,7 @@ import { } from "@mui/joy"; import Button from "@mui/material/Button"; import Stack from "@mui/material/Stack"; +import { updateProfile } from "firebase/auth"; import React, { useState } from "react"; export default function NameUpdate({ @@ -23,6 +24,7 @@ export default function NameUpdate({ const { user } = useUser(); const handleNameUpdate = async (event: React.FormEvent) => { event.preventDefault(); + const response = await fetch(`${functionsEndpoint}/user/${user?.uid}`, { method: "PUT", headers: { @@ -31,6 +33,15 @@ export default function NameUpdate({ }, body: JSON.stringify({ name: newName }), }); + + // Firebase Authentication の displayName を更新 + if (auth.currentUser) { + await updateProfile(auth.currentUser, { displayName: newName }); + console.log("Firebase displayName updated successfully"); + } else { + console.error("Failed to update displayName: No authenticated user"); + } + if (!response.ok) { console.error("Failed to update name"); } else { diff --git a/src/utils/Auth/signUpWithMail.ts b/src/utils/Auth/signUpWithMail.ts index bd9ef2f..b0b58f9 100644 --- a/src/utils/Auth/signUpWithMail.ts +++ b/src/utils/Auth/signUpWithMail.ts @@ -4,6 +4,7 @@ import { updateUser } from "@/utils/UserContext"; import { createUserWithEmailAndPassword, sendEmailVerification, + updateProfile, } from "firebase/auth"; /** @@ -24,6 +25,14 @@ export const signUpWithMail = ( // Signed up const user = userCredential.user; + // Firebase AuthのdisplayNameを設定 + try { + await updateProfile(user, { displayName: name }); + console.log("ユーザー名を設定しました:", name); + } catch (profileUpdateError) { + console.error("プロファイル更新に失敗しました:", profileUpdateError); + } + // uidとdocument IDを一致させる await createUser(name, user.uid); updateUser({