Skip to content

Commit

Permalink
#2 feat: Kakao Login SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryVoid committed Oct 21, 2024
1 parent 9ea23aa commit be8a90e
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Climeet-iOS/Climeet-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
0489EE932C2EA04500BFC55B /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 0489EE922C2EA04500BFC55B /* Alamofire */; };
0489EE962C2EA05900BFC55B /* ComposableArchitecture in Frameworks */ = {isa = PBXBuildFile; productRef = 0489EE952C2EA05900BFC55B /* ComposableArchitecture */; };
0489EE9C2C2EA18D00BFC55B /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 0489EE9B2C2EA18D00BFC55B /* Kingfisher */; };
6C566F532CC67C990064299C /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 6C566F522CC67C990064299C /* KakaoSDKAuth */; };
6C566F552CC67C990064299C /* KakaoSDKCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 6C566F542CC67C990064299C /* KakaoSDKCommon */; };
6C566F572CC67C990064299C /* KakaoSDKUser in Frameworks */ = {isa = PBXBuildFile; productRef = 6C566F562CC67C990064299C /* KakaoSDKUser */; };
6CB868862CBBE6B8008D0BA5 /* DesignSystem in Frameworks */ = {isa = PBXBuildFile; productRef = 6CB868852CBBE6B8008D0BA5 /* DesignSystem */; };
6CFF85E62CB22A5400572F2E /* NetworkKit in Frameworks */ = {isa = PBXBuildFile; productRef = 6CFF85E52CB22A5400572F2E /* NetworkKit */; };
B94EC2422BD1473E00DC3FDB /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = B94EC2412BD1473E00DC3FDB /* .swiftlint.yml */; };
Expand Down Expand Up @@ -83,12 +86,15 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6C566F552CC67C990064299C /* KakaoSDKCommon in Frameworks */,
6C566F532CC67C990064299C /* KakaoSDKAuth in Frameworks */,
6CFF85E62CB22A5400572F2E /* NetworkKit in Frameworks */,
0489EE9C2C2EA18D00BFC55B /* Kingfisher in Frameworks */,
0489EE932C2EA04500BFC55B /* Alamofire in Frameworks */,
6CB868862CBBE6B8008D0BA5 /* DesignSystem in Frameworks */,
0489EE962C2EA05900BFC55B /* ComposableArchitecture in Frameworks */,
D45EB2462BFE10BD00BDC871 /* (null) in Frameworks */,
6C566F572CC67C990064299C /* KakaoSDKUser in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -193,6 +199,9 @@
0489EE9B2C2EA18D00BFC55B /* Kingfisher */,
6CFF85E52CB22A5400572F2E /* NetworkKit */,
6CB868852CBBE6B8008D0BA5 /* DesignSystem */,
6C566F522CC67C990064299C /* KakaoSDKAuth */,
6C566F542CC67C990064299C /* KakaoSDKCommon */,
6C566F562CC67C990064299C /* KakaoSDKUser */,
);
productName = "Climeet-iOS";
productReference = B94EC2222BD13CBB00DC3FDB /* Climeet-iOS.app */;
Expand Down Expand Up @@ -236,6 +245,7 @@
0489EE972C2EA0A100BFC55B /* XCRemoteSwiftPackageReference "Kingfisher" */,
6CFF85E42CB22A5400572F2E /* XCLocalSwiftPackageReference "../NetworkKit" */,
6CB868842CBBE6B8008D0BA5 /* XCLocalSwiftPackageReference "../DesignSystem" */,
6C566F512CC67C980064299C /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */,
);
productRefGroup = B94EC2232BD13CBB00DC3FDB /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -704,6 +714,14 @@
minimumVersion = 7.12.0;
};
};
6C566F512CC67C980064299C /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kakao/kakao-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.23.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -722,6 +740,21 @@
package = 0489EE972C2EA0A100BFC55B /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher;
};
6C566F522CC67C990064299C /* KakaoSDKAuth */ = {
isa = XCSwiftPackageProductDependency;
package = 6C566F512CC67C980064299C /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */;
productName = KakaoSDKAuth;
};
6C566F542CC67C990064299C /* KakaoSDKCommon */ = {
isa = XCSwiftPackageProductDependency;
package = 6C566F512CC67C980064299C /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */;
productName = KakaoSDKCommon;
};
6C566F562CC67C990064299C /* KakaoSDKUser */ = {
isa = XCSwiftPackageProductDependency;
package = 6C566F512CC67C980064299C /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */;
productName = KakaoSDKUser;
};
6CB868852CBBE6B8008D0BA5 /* DesignSystem */ = {
isa = XCSwiftPackageProductDependency;
productName = DesignSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "5be142813986199e75926d9db7cdd9e2cf26adf678ec601b319549972fda041c",
"originHash" : "9e5bcffc27643cc7fa51918467b96483bf7a919f8fc77ac91daa8115eac2ab43",
"pins" : [
{
"identity" : "alamofire",
Expand All @@ -19,6 +19,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "kakao-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kakao/kakao-ios-sdk",
"state" : {
"revision" : "ab4309c1950550add307046ad1e08024c7514603",
"version" : "2.23.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
Expand Down
94 changes: 94 additions & 0 deletions Climeet-iOS/Climeet-iOS/Data/Client/KakaoClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// KakaoClient.swift
// Climeet-iOS
//
// Created by 송형욱 on 10/21/24.
//

import Dependencies
import KakaoSDKUser
import KakaoSDKAuth
import KakaoSDKCommon

struct KakaoClient {
var login: @Sendable () async -> Result<String, AppError>
var me: @Sendable () async -> Result<KakaoDTO.Response, AppError>
}

extension KakaoClient {
private static func login() async throws -> String {
return try await withCheckedThrowingContinuation { continuation in
if UserApi.isKakaoTalkLoginAvailable() {
UserApi.shared.loginWithKakaoTalk { oauthToken, error in
if let error {
continuation.resume(throwing: error)
}
if let oauthToken {
continuation.resume(returning: oauthToken.accessToken)
}
}
} else {
UserApi.shared.loginWithKakaoAccount { oauthToken, error in
if let error {
continuation.resume(throwing: error)
}
if let oauthToken {
continuation.resume(returning: oauthToken.accessToken)
}
}
}
}
}

private static func myInfo() async throws -> User {
return try await withCheckedThrowingContinuation { continuation in
UserApi.shared.me { user, error in
if let error {
continuation.resume(throwing: error)
}
if let user {
continuation.resume(returning: user)
}
}
}
}
}

extension KakaoClient: DependencyKey {
static public var liveValue: KakaoClient = .init(
login: {
do {
let oAuthToken = try await KakaoClient.login()
return .success(oAuthToken)
} catch {
return .failure(AppError.dataParsingError("Kakao OAuthToken 호출 실패"))
}
},
me: {
do {
let user: User = try await KakaoClient.myInfo()
let birthYear = user.kakaoAccount?.birthyear ?? ""
let birthDay = user.kakaoAccount?.birthday ?? ""
return .success(KakaoDTO.Response(
id: user.id,
imageURL: user.kakaoAccount?.profile?.profileImageUrl?.absoluteString,
name: user.kakaoAccount?.name,
nickname: user.kakaoAccount?.profile?.nickname,
email: user.kakaoAccount?.email,
birthDay: birthYear + birthDay,
gender: user.kakaoAccount?.gender?.rawValue,
phoneNumber: user.kakaoAccount?.phoneNumber
))
} catch {
return .failure(AppError.dataParsingError("Kakao User Profile 호출 실패"))
}
}
)
}

extension DependencyValues {
var kakaoClient: KakaoClient {
get { self[KakaoClient.self] }
set { self[KakaoClient.self] = newValue }
}
}
22 changes: 22 additions & 0 deletions Climeet-iOS/Climeet-iOS/Data/DTO/Kakao/KakaoDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// KakaoDTO.swift
// Climeet-iOS
//
// Created by 송형욱 on 10/21/24.
//

import Foundation

enum KakaoDTO {
struct Response: Equatable {
var id: Int64?
var imageURL: String?
var name: String?
var nickname: String?
var email: String?
var birthDay: String?
var gender: String?
var phoneNumber: String?
var ageRange: String?
}
}

0 comments on commit be8a90e

Please sign in to comment.