Skip to content

Commit

Permalink
[WEAV-100] SMS 발송 및 인증 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Oct 8, 2024
1 parent ddee33c commit 3691613
Show file tree
Hide file tree
Showing 25 changed files with 2,880 additions and 858 deletions.
732 changes: 693 additions & 39 deletions OpenApiGenerator/Sources/OpenapiGenerated/Client.swift

Large diffs are not rendered by default.

2,543 changes: 1,880 additions & 663 deletions OpenApiGenerator/Sources/OpenapiGenerated/Types.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion OpenApiGenerator/Sources/openapi-generator-cli/3days-oas
5 changes: 4 additions & 1 deletion Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ let infoPlist = InfoPlist.extendingDefault(
"App Enviroment": "$(APP_ENV)",
"CFBundleDisplayName": "${INFOPLIST_KEY_CFBundleDisplayName}",
"UIUserInterfaceStyle": "Light",
"ITSAppUsesNonExemptEncryption": false
"ITSAppUsesNonExemptEncryption": false,
"NSAppTransportSecurity": [
"NSAllowsArbitraryLoads": true
]
]
)

Expand Down
4 changes: 2 additions & 2 deletions Projects/App/Sources/Navigation/NavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ extension PathType {
switch subView {
case .authPhoneInput:
AuthPhoneInputView()
case .authPhoneVerify:
AuthPhoneVerifyView()
case .authPhoneVerify(let smsResponse):
AuthPhoneVerifyView(smsResponse)
case .authAgreement:
AuthAgreementView()

Expand Down
9 changes: 5 additions & 4 deletions Projects/Core/CommonKit/Sources/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public final class AppCoordinator: ObservableObject {
//MARK: - Methods
@MainActor
public func changeRootView(_ path: PathType) {
push(path)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // 애니메이션 시간에 맞춰 조정
self.navigationStack.removeSubrange(0 ..< self.navigationStack.count - 1)
}
navigationStack = [path]
// push(path)
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
// self.navigationStack.removeSubrange(0 ..< self.navigationStack.count - 1)
// }
}

@MainActor
Expand Down
35 changes: 0 additions & 35 deletions Projects/Core/CommonKit/Sources/Navigation+Ext.swift

This file was deleted.

26 changes: 25 additions & 1 deletion Projects/Core/CommonKit/Sources/Path/PathTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import Model

public enum PathType: Hashable {
case designPreview
Expand Down Expand Up @@ -42,11 +43,34 @@ public enum PathType: Hashable {

public enum SignUpSubViewType: Hashable {
case authPhoneInput
case authPhoneVerify
case authPhoneVerify(SMSSendResponse)
case authAgreement

case authGreeting
case authProfileGender
case authProfileAge
case authName

public static func == (lhs: SignUpSubViewType, rhs: SignUpSubViewType) -> Bool {
return lhs.hashValue == rhs.hashValue
}

public func hash(into hasher: inout Hasher) {
switch self {
case .authPhoneInput:
hasher.combine(0)
case .authPhoneVerify:
hasher.combine(1)
case .authAgreement:
hasher.combine(2)
case .authGreeting:
hasher.combine(3)
case .authProfileGender:
hasher.combine(4)
case .authProfileAge:
hasher.combine(5)
case .authName:
hasher.combine(6)
}
}
}
30 changes: 30 additions & 0 deletions Projects/Core/Model/Sources/Network/SMSSendResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SMSSendResponse.swift
// CoreKit
//
// Created by 김지수 on 10/9/24.
// Copyright © 2024 com.weave. All rights reserved.
//

import Foundation

public enum UserType: String {
case NEW = "NEW"
case EXISTING = "EXISTING"
}

public struct SMSSendResponse {
public let userType: UserType
public let authCodeId: String
public let phoneNumber: String

public init(
userType: UserType,
authCodeId: String,
phoneNumber: String
) {
self.userType = userType
self.authCodeId = authCodeId
self.phoneNumber = phoneNumber
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import Foundation

public struct SMSVerificationResponse {
let refreshToken: String
let accessToken: String
public struct ExistingUserVerificationResponse {
public let refreshToken: String
public let accessToken: String

public init(refreshToken: String, accessToken: String) {
self.refreshToken = refreshToken
self.accessToken = accessToken
}
}
76 changes: 0 additions & 76 deletions Projects/Core/NetworkKit/Sources/AuthService/AuthEndpoint.swift

This file was deleted.

80 changes: 80 additions & 0 deletions Projects/Core/NetworkKit/Sources/AuthService/AuthService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// AuthService.swift
// NetworkKit
//
// Created by 김지수 on 8/25/24.
// Copyright © 2024 com.studentcenter. All rights reserved.
//

import Foundation
import Model
import CoreKit

enum AuthEndpointError: Error {
case emptyToken
case tokenResponseNotValid
}

public enum AuthService: Endpointable {
public static func requestSendSMS(phone: String) async throws -> SMSSendResponse {
let response = try await client.requestVerification(
headers: .init(X_hyphen_OS_hyphen_Type: .IOS),
body: .json(.init(phoneNumber: phone))
).created.body.json

return SMSSendResponse(
userType: UserType(
rawValue: response.userStatus?.rawValue ?? "NEW"
) ?? .NEW,
authCodeId: response.authCodeId,
phoneNumber: phone
)
}

public static func requestNewUserVerifyCode(
_ request: SMSVerificationRequest
) async throws -> String {
let response = try await client.newUserVerifyCode(
path: .init(authCodeId: request.verificationId),
body: .json(.init(verificationCode: request.verificationCode))
).ok.body.json
return response.registerToken
}

public static func requestExistingUserVerifyCode(
_ request: SMSVerificationRequest
) async throws -> ExistingUserVerificationResponse {
let response = try await client.existingUserVerifyCode(
path: .init(authCodeId: request.verificationId),
body: .json(.init(verificationCode: request.verificationCode))
).ok.body.json

return ExistingUserVerificationResponse(
refreshToken: response.refreshToken,
accessToken: response.accessToken
)
}
}

//MARK: - AccessToken Refresh
extension AuthService {
static func refreshAccessToken() async throws -> RefreshTokenResponse {
guard let refreshToken = TokenManager.refreshToken else {
throw AuthEndpointError.emptyToken
}

let response = try await client.refreshToken(
body: .json(.init(refreshToken: refreshToken))
)

let result = try response.ok.body.json

TokenManager.accessToken = result.accessToken
TokenManager.refreshToken = result.refreshToken

return RefreshTokenResponse(
refreshToken: result.refreshToken,
accessToken: result.accessToken
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ actor LoggingMiddleware {
private let logger: Logger
package let bodyLoggingPolicy: BodyLoggingPolicy

package init(logger: Logger = defaultLogger, bodyLoggingConfiguration: BodyLoggingPolicy = .never) {
package init(logger: Logger = defaultLogger, bodyLoggingConfiguration: BodyLoggingPolicy = .upTo(maxBytes: 2048)) {
self.logger = logger
self.bodyLoggingPolicy = bodyLoggingConfiguration
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extension RetryingMiddleware: ClientMiddleware {

// 토큰 갱신 시도
do {
let tokenResponse = try await AuthEndpoint.refreshAccessToken()
let tokenResponse = try await AuthService.refreshAccessToken()
guard let accesstoken = tokenResponse.accessToken,
let refreshToken = tokenResponse.refreshToken else {
throw AuthEndpointError.tokenResponseNotValid
Expand Down
9 changes: 9 additions & 0 deletions Projects/DesignSystem/DesignCore/Sources/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ public extension View {
)
)
}

func setPopNavigation(handler: @escaping () -> Void) -> some View {
return modifier(
NavigationBarViewModifier(
showLeftBackButton: true,
handler: handler
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public struct AuthAgreementView: View {
.ignoresSafeArea(.all)
.padding(.top, 14)
.textureBackground()
.setNavigationWithPop()
.setPopNavigation {
AppCoordinator.shared.pop()
}
.setLoading(state.isLoading)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct AuthPhoneInputView: View {
let model = AuthPhoneInputModel()
let intent = AuthPhoneInputIntent(
model: model,
externalData: .init(input: "temp")
externalData: .init()
)
let container = MVIContainer(
intent: intent as AuthPhoneInputIntent.Intentable,
Expand Down Expand Up @@ -53,7 +53,7 @@ public struct AuthPhoneInputView: View {
title: "다음",
isActive: state.isPhoneValidated
) {
intent.onTapNextButton()
intent.onTapNextButton(with: state.phoneInputText)
}
}
.task {
Expand All @@ -65,7 +65,9 @@ public struct AuthPhoneInputView: View {
.ignoresSafeArea(.all)
.padding(.top, 14)
.textureBackground()
.setNavigationWithPop()
.setPopNavigation {
AppCoordinator.shared.pop()
}
.setLoading(state.isLoading)
}
}
Expand Down
Loading

0 comments on commit 3691613

Please sign in to comment.