From dcf70cab05de9930d3afa1db3abcea0427229115 Mon Sep 17 00:00:00 2001 From: Phangg Date: Tue, 26 Mar 2024 10:33:20 +0900 Subject: [PATCH] =?UTF-8?q?[Edit]=20fcmToken=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20#166?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 회원가입 시, fcmToken 바로 받아오지 못하는 문제 수정 - currentUser 를 받아오는 것이, 로그인 완료 시점보다 뒤에 있었던 문제 --- JUDA_iOS/JUDA/Model/User.swift | 8 ++++++++ JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift | 4 ++-- JUDA_iOS/JUDA/View/Main/MainView.swift | 5 +++++ JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift | 10 +++++----- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/JUDA_iOS/JUDA/Model/User.swift b/JUDA_iOS/JUDA/Model/User.swift index f4b27c56..0699fa6a 100644 --- a/JUDA_iOS/JUDA/Model/User.swift +++ b/JUDA_iOS/JUDA/Model/User.swift @@ -8,6 +8,7 @@ import Foundation import FirebaseFirestore +// MARK: - User // Firebase users 컬렉션 데이터 모델 struct User { var userField: UserField @@ -29,6 +30,13 @@ struct UserField: Codable { var authProviders: String // AuthProviderOption - rawValue } +extension User: Equatable { + static func == (lhs: User, rhs: User) -> Bool { + lhs.userField.userID == rhs.userField.userID + } +} + +// MARK: - UserNotification struct UserNotification: Equatable { @DocumentID var userNotificationID: String? var notificationField: NotificationField diff --git a/JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift b/JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift index 7d2fc122..b7c6f2d9 100644 --- a/JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift +++ b/JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift @@ -60,7 +60,7 @@ struct ProfileSettingView: View { ScrollView { // 프로필 사진 선택 ZStack(alignment: .bottomTrailing) { - // TODO: - 프로필 사진 + // 프로필 사진 if let image = userProfileImage { Image(uiImage: image) .resizable() @@ -192,8 +192,8 @@ struct ProfileSettingView: View { notification: notificationAllowed ) authViewModel.isLoading = false + navigationRouter.clear() } - navigationRouter.back() } label: { Text("완료") .font(.medium20) diff --git a/JUDA_iOS/JUDA/View/Main/MainView.swift b/JUDA_iOS/JUDA/View/Main/MainView.swift index e9d1972c..50ba3e0a 100644 --- a/JUDA_iOS/JUDA/View/Main/MainView.swift +++ b/JUDA_iOS/JUDA/View/Main/MainView.swift @@ -84,6 +84,11 @@ struct MainView: View { // 로그인 한 경우 알림권한 받아옴 if newValue { appViewModel.setUserNotificationOption() + } + } + .onChange(of: authViewModel.currentUser) { _ in + // fcmToken 받아오기 + if authViewModel.signInStatus { Task { if let user = authViewModel.currentUser?.userField, let uid = user.userID { diff --git a/JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift b/JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift index 31c28a6f..78aedd3b 100644 --- a/JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift +++ b/JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift @@ -154,13 +154,13 @@ final class AuthViewModel: ObservableObject { // 프로필 이미지 storage 저장 let url = await uploadProfileImageToStorage(image: profileImage) // 유저 이름, 생일, 성별, 프로필, 알림 동의 등 forestore 에 저장 - addUserDataToStore( + await addUserDataToStore( name: name, age: age, profileImageURL: url, gender: gender, notification: notification - ) + ) // 유저 데이터 받기 await getCurrentUser() } catch { @@ -444,7 +444,7 @@ extension AuthViewModel { extension AuthViewModel { // 유저 정보 저장 func addUserDataToStore(name: String, age: Int, profileImageURL: URL?, - gender: String, notification: Bool) { + gender: String, notification: Bool) async { do { let uid = try checkCurrentUserID() firebaseAuthService.addUserDataToStore( @@ -567,8 +567,8 @@ extension AuthViewModel { private func deleteAppleAccount() async -> Bool { do { guard try getProviderOptionString() == AuthProviderOption.apple.rawValue else { return false } + let uid = try checkCurrentUserID() try await firebaseAuthService.deleteAccountWithApple() - let uid = try checkCurrentUserID() firebaseAuthService.deleteUserData(uid: uid) resetData() return true @@ -621,8 +621,8 @@ extension AuthViewModel { private func deleteGoogleAccount() async -> Bool { do { guard try getProviderOptionString() == AuthProviderOption.google.rawValue else { return false } - try await firebaseAuthService.deleteAccountWithGoogle() let uid = try checkCurrentUserID() + try await firebaseAuthService.deleteAccountWithGoogle() firebaseAuthService.deleteUserData(uid: uid) resetData() return true