Skip to content

Commit

Permalink
Merge pull request #28 from DeveloperAcademy-POSTECH/20-feat-settingv…
Browse files Browse the repository at this point in the history
…iew-logic-구현

[Feat] SettingView logic 구현 #20
  • Loading branch information
Theodore2024 authored Aug 1, 2024
2 parents 3b47c8c + 2b92d4e commit f62ad8f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions TeemonDeo/Services/AuthenticationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ final class AuthenticationManager {
}
try await user.delete()
}

//추가: SSO 로그인 정보와 동일한 유저를 firebase에서 찾아서 return
func getChallnegeUser() throws -> ChallengeUser {
let challnegeUser = try getAuthenticatedUser()
return ChallengeUser(auth: challnegeUser)
}
}

// MARK: SIGN IN SSO (SSO: Sigle Sign On)
Expand Down
10 changes: 10 additions & 0 deletions TeemonDeo/ViewModels/SettingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ final class SettingsViewModel: ObservableObject {

@Published var authProviders: [AuthProviderOption] = []
@Published var authUser: AuthDataResultModel? = nil
//추가
@Published var challengeUser: ChallengeUser? = nil


func loadAuthProviders() {
if let providers = try? AuthenticationManager.shared.getProviders() {
Expand All @@ -20,6 +23,7 @@ final class SettingsViewModel: ObservableObject {
}

func loadAuthUser() {
// SSO 로그인 정보 가져오기
self.authUser = try? AuthenticationManager.shared.getAuthenticatedUser()
}

Expand All @@ -30,4 +34,10 @@ final class SettingsViewModel: ObservableObject {
func deleteAccount() async throws {
try await AuthenticationManager.shared.delete()
}

// Friebase에서 유저 정보 가져오기
func loadChallnegeUser() {
self.challengeUser = try? AuthenticationManager.shared.getChallnegeUser()
}

}
22 changes: 9 additions & 13 deletions TeemonDeo/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@
import SwiftUI

struct ContentView: View {

@StateObject private var viewModel = SettingsViewModel()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, Daisy!")
// Text("\())")
Text("유저 uid : \(viewModel.challengeUser?.userId ?? "혹시나 에러 났을 때를 대비한 디폴트 값")")
Text("유저 email : \(viewModel.challengeUser?.userEmail ?? "혹시나 에러 났을 때를 대비한 디폴트 값")")
Text("유저 닉네임 : \(viewModel.challengeUser?.userNickname ?? "혹시나 에러 났을 때를 대비한 디폴트 값")")
Text("유저 uid : \(viewModel.challengeUser?.userTier ?? 111)") //유저 못 불러오면 111로 뜸
}
.onAppear(){
viewModel.loadChallnegeUser()
}
// .onAppear{
// UserManager.shared.getUser(userId: <#T##String#>)
// }
.padding()
// .onAppear() {
//
// }


// LottieView(filename: "Splash")
// .ignoresSafeArea(.all)
Expand Down
15 changes: 10 additions & 5 deletions TeemonDeo/Views/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct SettingView: View {
}
.padding(.horizontal)


// 로그아웃, 계정삭제 버튼
List {
// 로그아웃 버튼
Button("Log out") {
Expand Down Expand Up @@ -87,8 +87,8 @@ struct SettingView: View {
}
}
.onAppear {
// 어떤 SSO로 로그인했는지 확인
viewModel.loadAuthProviders()
viewModel.loadAuthUser()
}
}
.navigationBarItems(leading: Text("관리").font(.title).fontWeight(.bold))
Expand All @@ -98,17 +98,18 @@ struct SettingView: View {
}

struct profileView: View {
@StateObject private var viewModel = SettingsViewModel()
var body: some View {
HStack(spacing: 10) {
Image("defaultProfileImage")
.resizable()
.frame(maxWidth: 60, maxHeight: 60)

VStack(alignment: .leading, spacing: 10) {
Text("누구길래티몬데오")
Text(viewModel.challengeUser?.userNickname ?? "유저닉네임")
.font(.headline)
.fontWeight(.bold)
Text("🎖️ 개쩌는 티어")
Text("🎖️ 개쩌는 티어: \(viewModel.challengeUser?.userTier ?? 111)")
.font(.footnote)
.foregroundStyle(.blue)
}
Expand All @@ -129,7 +130,11 @@ struct profileView: View {
}
})
.padding(.bottom, 30)
}.padding(.horizontal)
}
.padding(.horizontal)
.onAppear(){
viewModel.loadChallnegeUser()
}
}
}

Expand Down

0 comments on commit f62ad8f

Please sign in to comment.