Skip to content

Commit

Permalink
✨ :: [#48] Add AuthViewModel SignIn Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Xixn2 committed Nov 9, 2024
1 parent 59fa9f4 commit cb9e64c
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 154 deletions.
1 change: 0 additions & 1 deletion Projects/App/Sources/Application/ExpoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ struct ExpoApp: App {
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PostDetailView.swift
// Expo-iOS
//
// Created by 서지완 on 11/6/24.
// Copyright © 2024 SchoolofCompany. All rights reserved.
//

import SwiftUI

struct PostDetailView: View {
var body: some View {
VStack(spacing: 0) {
ExpoIOSAsset.Assets.leftBackButton.swiftUIImage

Spacer()
}
}
}

#Preview {
PostDetailView()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ import Domain
import Foundation

public final class AuthViewModel: ObservableObject {

private let authProvider = MoyaProvider<AuthAPI>()
//private let accountProvider = MoyaProvider<AccountServices>()

//public override init() {}

var userData: SigninModel?
private var email: String = ""
//public let profileModel = ProfileViewModel()

private var password: String = ""
private var authCode: String = ""
Expand Down Expand Up @@ -85,6 +80,43 @@ public final class AuthViewModel: ObservableObject {
self.major = major
}

func signIn(completion: @escaping (Int, String?) -> Void) {
let param = SigninRequest(nickname: email, password: password)
authProvider.request(.signIn(param: param)) { [weak self] response in
guard let self = self else { return }

DispatchQueue.global().async {
switch response {
case .success(let result):
let statusCode = result.statusCode
do {
switch statusCode {
case 200:
print(self.password)
let signInResponse = try result.map(SigninResponse.self)
KeyChain.shared.create(key: Const.KeyChainKey.accessToken, token: signInResponse.refreshToken)
KeyChain.shared.create(key: Const.KeyChainKey.refreshToken, token: signInResponse.refreshToken)
completion(statusCode, nil)
default:
break
}
} catch {
print("Error parsing SignInResponse: \(error)")
}
DispatchQueue.main.async {
completion(statusCode, nil)
}

case .failure(let err):
print("Network error: \(err.localizedDescription)")
DispatchQueue.main.async {
completion(0, nil)
}
}
}
}
}

// MARK: - Sign Up
func signUp(completion: @escaping (Bool) -> Void) {
let params = SignupRequest(name: name, nickname: nickname, email: email, password: password, phoneNumber: phoneNumber)
Expand Down Expand Up @@ -173,12 +205,6 @@ public final class AuthViewModel: ObservableObject {
case 200..<300:
print("OK")
completion(true)
case 404:
print("인증 코드를 찾을 수 없을때 / 인증되지 않은 사용자일때 / 찾을 수 없는 사용자 일때")
completion(false)
case 429:
print("인증번호 검증 요청이 5번을 초과할 경우")
completion(false)
case 500:
print("SERVER ERROR")
completion(false)
Expand Down
Loading

0 comments on commit cb9e64c

Please sign in to comment.