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

サインアップ後にログインされるように修正 #75

Merged
merged 3 commits into from
Nov 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion app/src/app/camera/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const CameraApp = () => {
todayAssignment | undefined
>();
const [assignments, setAssignments] = useState<todayAssignment[]>([]);
const [isActive, setIsActive] = useState<boolean>(true);
const [isActive, setIsActive] = useState<boolean>(false);
const [isPointDialogOpen, _] = usePointDialog();
const openDialog = useOpenPointDialog();
const [loginUser, setLoginUser] = useState<User>();
Expand Down
16 changes: 7 additions & 9 deletions app/src/lib/signInAndUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const signInOrUp = async (firebaseUser: FirebaseUser) => {

if (res.status === 200) {
const userData = await res.json();

const user: DBUser = { ...userData };

if (userData) {
Expand All @@ -28,6 +27,8 @@ export const signInOrUp = async (firebaseUser: FirebaseUser) => {
}
} else if (res.status === 404) {
await signUp(firebaseUser);
// サインアップ後にユーザー情報を取得してログイン処理を行う
await signInOrUp(firebaseUser);
} else {
console.error(`Unexpected status code: ${res.status}`);
}
Expand All @@ -46,14 +47,11 @@ const signUp = async (user: User) => {
body: JSON.stringify(user),
});

const resUser = await res.json();

if (resUser) {
storeStorageUser(resUser);
toRoot();
} else {
throw new Error("ユーザー登録に失敗");
if (res.status === 200) {
// ユーザー登録が成功した場合は何もせず戻る
return;
}
throw new Error("ユーザー登録に失敗");
} catch (error) {
console.error("エラーが発生しました:", error);
}
Expand Down Expand Up @@ -81,4 +79,4 @@ const createExp = async (userId: number) => {

const toRoot = () => {
window.location.href = "/";
};
};
Loading