Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions DOKI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
766B2E492E254BD600F3A668 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 766B2E482E254BD600F3A668 /* Moya */; };
76C154E62EE46DDF00A8ED40 /* NMapsMap in Frameworks */ = {isa = PBXBuildFile; productRef = 76C154E52EE46DDF00A8ED40 /* NMapsMap */; };
76ECCF2D2E05C4820056CAF7 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 76ECCF2C2E05C4820056CAF7 /* Kingfisher */; };
76ECCF302E05C4CC0056CAF7 /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 76ECCF2F2E05C4CC0056CAF7 /* Lottie */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -43,6 +44,7 @@
buildActionMask = 2147483647;
files = (
76ECCF2D2E05C4820056CAF7 /* Kingfisher in Frameworks */,
76C154E62EE46DDF00A8ED40 /* NMapsMap in Frameworks */,
76ECCF302E05C4CC0056CAF7 /* Lottie in Frameworks */,
766B2E492E254BD600F3A668 /* Moya in Frameworks */,
);
Expand Down Expand Up @@ -90,6 +92,7 @@
76ECCF2C2E05C4820056CAF7 /* Kingfisher */,
76ECCF2F2E05C4CC0056CAF7 /* Lottie */,
766B2E482E254BD600F3A668 /* Moya */,
76C154E52EE46DDF00A8ED40 /* NMapsMap */,
);
productName = DoggyWalker;
productReference = 76ECCDED2E05AFCC0056CAF7 /* DOKI.app */;
Expand Down Expand Up @@ -123,6 +126,7 @@
76ECCF2B2E05C4820056CAF7 /* XCRemoteSwiftPackageReference "Kingfisher" */,
76ECCF2E2E05C4CC0056CAF7 /* XCRemoteSwiftPackageReference "lottie-ios" */,
766B2E472E254BD600F3A668 /* XCRemoteSwiftPackageReference "Moya" */,
76C154E42EE46DDF00A8ED40 /* XCRemoteSwiftPackageReference "SPM-NMapsMap" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 76ECCDEE2E05AFCC0056CAF7 /* Products */;
Expand Down Expand Up @@ -162,7 +166,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
BASE_URL = "www.pawkey.o-r.kr/api/v1/";
BASE_URL = "";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -228,7 +232,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
BASE_URL = "www.pawkey.o-r.kr/api/v1/";
BASE_URL = "";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -282,12 +286,15 @@
};
76ECCDF92E05AFCC0056CAF7 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReferenceAnchor = 76ECCDEF2E05AFCC0056CAF7 /* DOKI */;
baseConfigurationReferenceRelativePath = Config.xcconfig;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = DOKI/DOKI.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = Z9PQC69UPK;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = DOKI/Info.plist;
Expand Down Expand Up @@ -319,9 +326,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = DOKI/DOKI.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = Z9PQC69UPK;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = DOKI/Info.plist;
Expand Down Expand Up @@ -380,6 +388,14 @@
minimumVersion = 15.0.3;
};
};
76C154E42EE46DDF00A8ED40 /* XCRemoteSwiftPackageReference "SPM-NMapsMap" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/navermaps/SPM-NMapsMap";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.23.0;
};
};
76ECCF2B2E05C4820056CAF7 /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/onevcat/Kingfisher";
Expand All @@ -404,6 +420,11 @@
package = 766B2E472E254BD600F3A668 /* XCRemoteSwiftPackageReference "Moya" */;
productName = Moya;
};
76C154E52EE46DDF00A8ED40 /* NMapsMap */ = {
isa = XCSwiftPackageProductDependency;
package = 76C154E42EE46DDF00A8ED40 /* XCRemoteSwiftPackageReference "SPM-NMapsMap" */;
productName = NMapsMap;
};
76ECCF2C2E05C4820056CAF7 /* Kingfisher */ = {
isa = XCSwiftPackageProductDependency;
package = 76ECCF2B2E05C4820056CAF7 /* XCRemoteSwiftPackageReference "Kingfisher" */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DOKI/Application/DOKIApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
@main
struct DOKIApp: App {
@StateObject var appDIContainer = AppDIContainer()
@StateObject var authManager = AuthManager()
@StateObject var authManager = AuthManager.shared

var body: some Scene {
WindowGroup {
Expand Down
10 changes: 10 additions & 0 deletions DOKI/DOKI.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
59 changes: 56 additions & 3 deletions DOKI/Global/Manager/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,73 @@

import SwiftUI

import Moya

enum AuthState: String, CaseIterable {
case loggedIn
case loggedOut
case loading
}

class AuthManager: ObservableObject {
static let shared = AuthManager()

@Published var authStatus: AuthState = .loading

private(set) var accessToken: String?
private(set) var refreshToken: String?

private let provider = MoyaProvider<LoginAPI>(plugins: [NetworkLoggerPlugin()])

private init() {}

func checkLogin() {
authStatus = .loggedIn
do {
self.accessToken = try KeychainManager.read(.accessToken)
self.refreshToken = try KeychainManager.read(.refreshToken)
authStatus = .loggedIn
} catch {
authStatus = .loggedOut
print(error.localizedDescription)
}
}

func login() {
authStatus = .loggedIn
/// AppleLogin API
func loginWithApple(_ idToken: String, deviceId: String) async {
do {
let appleLoginReqDto = AppleLoginRequestDTO(idToken: idToken, deviceId: deviceId)
let response: AppleLoginResponseDTO = try await provider.async.request(.appleLogin(appleLoginReqDto: appleLoginReqDto))
try KeychainManager.create(.accessToken, response.accessToken)
try KeychainManager.create(.refreshToken, response.refreshToken)
self.accessToken = response.accessToken
self.refreshToken = response.refreshToken

authStatus = .loggedIn
} catch {
print(error.localizedDescription)
}
}

func logout() {
do {
try KeychainManager.delete(.accessToken)
try KeychainManager.delete(.refreshToken)
authStatus = .loggedOut
} catch {
print(error.localizedDescription)
}
}

func reissueToken(accessToken: String, refreshToken: String) {
do {
try KeychainManager.create(.accessToken, accessToken)
try KeychainManager.create(.refreshToken, refreshToken)
self.accessToken = accessToken
self.refreshToken = refreshToken
} catch {
print(error.localizedDescription)
}
}
}


81 changes: 81 additions & 0 deletions DOKI/Global/Manager/KeychainManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// KeychainManager.swift
// DOKI
//
// Created by a on 12/7/25.
//

import Foundation

enum KeychainError: Error {
case noPassword
case unhandledError(status: OSStatus)
case unexpectedPasswordData

var message: String {
switch self {
case .noPassword: return "No password available."
case .unexpectedPasswordData: return "Expected data, but found none."
case .unhandledError(let status): return "Unhandled error with status: \(status)"
}
}
}

enum KeychainName: String {
case accessToken
case refreshToken
}

struct KeychainManager {

/// Keychain 저장소에서 key에 해당하는 값을 추가
static func create<T: Codable>(_ key: KeychainName, _ value: T) throws {
do {
let valueData = try JSONEncoder().encode(value)
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccount: key.rawValue,
kSecValueData: valueData
]
SecItemDelete(query)

let status = SecItemAdd(query, nil)
guard status == errSecSuccess else { throw KeychainError.unhandledError(status: status) }
} catch {
throw KeychainError.unexpectedPasswordData
}
}

/// Keychain 저장소에서 key에 해당하는 값을 검색
@discardableResult
static func read(_ key: KeychainName) throws -> String? {
let query: NSDictionary = [kSecClass: kSecClassGenericPassword,
kSecAttrAccount: key.rawValue,
kSecMatchLimit: kSecMatchLimitOne,
kSecReturnData: true]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
guard status != errSecItemNotFound else { throw KeychainError.noPassword }
if status == errSecSuccess {
if let retrievedItem = item as? Data {
let returnValue = String(data: retrievedItem, encoding: String.Encoding.utf8)
return returnValue
} else {
return nil
}
} else {
throw KeychainError.unexpectedPasswordData
}
}

/// key에 해당하는 값을 삭제
static func delete(_ key: KeychainName) throws {
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccount: key.rawValue
]
let status = SecItemDelete(query)
guard status == errSecSuccess else { throw KeychainError.unhandledError(status: status) }
}
}

Loading