Skip to content

Commit

Permalink
[Edit] fcmToken 에러 수정 #166
Browse files Browse the repository at this point in the history
회원가입 시, fcmToken 바로 받아오지 못하는 문제 수정
- currentUser 를 받아오는 것이, 로그인 완료 시점보다 뒤에 있었던 문제
  • Loading branch information
Phangg committed Mar 26, 2024
1 parent 8e25da9 commit dcf70ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 8 additions & 0 deletions JUDA_iOS/JUDA/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import FirebaseFirestore

// MARK: - User
// Firebase users 컬렉션 데이터 모델
struct User {
var userField: UserField
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions JUDA_iOS/JUDA/View/LogIn/ProfileSettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct ProfileSettingView: View {
ScrollView {
// 프로필 사진 선택
ZStack(alignment: .bottomTrailing) {
// TODO: - 프로필 사진
// 프로필 사진
if let image = userProfileImage {
Image(uiImage: image)
.resizable()
Expand Down Expand Up @@ -192,8 +192,8 @@ struct ProfileSettingView: View {
notification: notificationAllowed
)
authViewModel.isLoading = false
navigationRouter.clear()
}
navigationRouter.back()
} label: {
Text("완료")
.font(.medium20)
Expand Down
5 changes: 5 additions & 0 deletions JUDA_iOS/JUDA/View/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions JUDA_iOS/JUDA/ViewModel/Auth/AuthViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcf70ca

Please sign in to comment.