Skip to content

Commit aa05696

Browse files
authored
[#242] 애플 계정의 끊기가 실패하는 이슈를 해결한다 (#243)
* fix: getAppleConfiguration()을 통해 애플 관련 키를 가져오도록 수정하여 해결 * feat: 에러가 날 수 있는 코드의 상단에 Logger 추가 * style: 인덴트 개선
1 parent 53411ba commit aa05696

4 files changed

Lines changed: 42 additions & 24 deletions

File tree

DevLog/Infra/Service/SocialLogin/AppleAuthenticationService.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,31 @@ final class AppleAuthenticationService: AuthenticationService {
144144
}
145145

146146
func unlink(_ uid: String) async throws {
147-
let accessToken = try await refreshAppleAccessToken()
147+
do {
148+
logger.info("Starting Apple access token refresh for unlink. uid: \(uid)")
149+
let accessToken = try await refreshAppleAccessToken()
148150

149-
try await revokeAppleAccessToken(token: accessToken)
151+
logger.info("Starting Apple access token revocation for unlink. uid: \(uid)")
152+
try await revokeAppleAccessToken(token: accessToken)
150153

151-
let tokensRef = store.document("users/\(uid)/userData/tokens")
154+
let tokensRef = store.document("users/\(uid)/userData/tokens")
152155

153-
let doc = try await tokensRef.getDocument()
156+
logger.info("Starting Apple token document fetch for unlink. uid: \(uid)")
157+
let doc = try await tokensRef.getDocument()
154158

155-
if doc.exists {
156-
try await tokensRef.updateData([
157-
"appleRefreshToken": FieldValue.delete()
158-
])
159-
}
159+
if doc.exists {
160+
logger.info("Starting Apple refresh token deletion from Firestore for unlink. uid: \(uid)")
161+
try await tokensRef.updateData([
162+
"appleRefreshToken": FieldValue.delete()
163+
])
164+
}
160165

161-
_ = try await user?.unlink(fromProvider: providerID.rawValue)
166+
logger.info("Starting Firebase Apple provider unlink. uid: \(uid)")
167+
_ = try await user?.unlink(fromProvider: providerID.rawValue)
168+
} catch {
169+
logger.error("Failed to unlink Apple account", error: error)
170+
throw error
171+
}
162172
}
163173

164174
// Apple 인증 메서드

DevLog/Infra/Service/SocialLogin/GithubAuthenticationService.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,17 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
126126
}
127127

128128
func unlink(_ uid: String) async throws {
129-
logger.info("Unlinking GitHub account for user: \(uid)")
130-
131129
do {
130+
logger.info("Starting GitHub access token revocation for unlink. uid: \(uid)")
132131
try await revokeAccessToken()
133132

134133
let tokensRef = store.document("users/\(uid)/userData/tokens")
135134

135+
logger.info("Starting GitHub access token deletion from Firestore for unlink. uid: \(uid)")
136136
try await tokensRef.updateData(["githubAccessToken": FieldValue.delete()])
137137

138+
logger.info("Starting Firebase GitHub provider unlink. uid: \(uid)")
138139
_ = try await user?.unlink(fromProvider: providerID.rawValue)
139-
140-
logger.info("Successfully unlinked GitHub account")
141140
} catch {
142141
logger.error("Failed to unlink GitHub account", error: error)
143142
throw error

DevLog/Infra/Service/SocialLogin/GoogleAuthenticationService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ final class GoogleAuthenticationService: AuthenticationService {
119119
}
120120

121121
func unlink(_ uid: String) async throws {
122+
logger.info("Starting Google disconnect for unlink. uid: \(uid)")
122123
GIDSignIn.sharedInstance.signOut()
123124
try await GIDSignIn.sharedInstance.disconnect()
124125

126+
logger.info("Starting Firebase Google provider unlink. uid: \(uid)")
125127
_ = try await user?.unlink(fromProvider: AuthProviderID.google.rawValue)
126128
}
127129

Firebase/functions/src/auth/apple.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,19 @@ export const revokeAppleAccessToken = onCall({
277277

278278
try {
279279
const { token } = request.data;
280-
const { teamId, clientId, keyId, privateKey } = getAppleConfiguration();
281280

282281
if (!token) {
283282
throw new HttpsError("invalid-argument", "Token is required");
284283
}
285284

286-
// JWT 생성
285+
console.log("Starting Apple token revocation", {
286+
uid: request.auth.uid
287+
});
288+
289+
console.log("Starting Apple configuration load for token revocation");
290+
const { teamId, clientId, keyId, privateKey } = getAppleConfiguration();
291+
292+
console.log("Starting Apple client secret creation for token revocation");
287293
const clientSecret = jwt.sign({}, privateKey, {
288294
algorithm: "ES256",
289295
expiresIn: "5m",
@@ -293,14 +299,15 @@ export const revokeAppleAccessToken = onCall({
293299
keyid: keyId,
294300
});
295301

296-
// Apple 서버에 토큰 취소 요청
297-
await axios.post("https://appleid.apple.com/auth/revoke",
298-
new URLSearchParams({
299-
client_id: clientId,
300-
client_secret: clientSecret,
301-
token: token,
302-
token_type_hint: "access_token" // access_token 또는 refresh_token 지정 가능
303-
}).toString(), {
302+
console.log("Starting Apple revoke API request");
303+
await axios.post(
304+
"https://appleid.apple.com/auth/revoke",
305+
new URLSearchParams({
306+
client_id: clientId,
307+
client_secret: clientSecret,
308+
token: token,
309+
token_type_hint: "access_token" // access_token 또는 refresh_token 지정 가능
310+
}).toString(), {
304311
headers: {"Content-Type": "application/x-www-form-urlencoded"},
305312
});
306313

0 commit comments

Comments
 (0)