Skip to content

Commit 8c36c4b

Browse files
authored
[#69] 깃헙 OAuth 로그인, 로그아웃이 안되는 버그를 해결한다 (#131)
* style: 코드 인덴트 추가 * style: Url -> URL * feat: 성공했을 시 로그 추가 * chore: 업데이트 * feat: 배포 시 .env 내용으로 항상 업데이트 하도록 추가
1 parent 468b380 commit 8c36c4b

5 files changed

Lines changed: 42 additions & 23 deletions

File tree

DevLog/Infra/Service/SocialLogin/GithubAuthenticationService.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
3737
logger.debug("Signing in with custom token")
3838
let result = try await Auth.auth().signIn(withCustomToken: customToken)
3939

40-
// 4. Firebase Auth 사용자 프로필 업데이트
41-
let githubUser = try await requestUserProfile(accessToken: accessToken)
42-
43-
if let photoURL = githubUser.avatarUrl, let url = URL(string: photoURL) {
44-
let changeRequest = result.user.createProfileChangeRequest()
45-
changeRequest.photoURL = url
46-
changeRequest.displayName = githubUser.name ?? githubUser.login
47-
try await changeRequest.commitChanges()
48-
}
40+
// 4. Firebase Auth 사용자 프로필 업데이트
41+
let githubUser = try await requestUserProfile(accessToken: accessToken)
42+
43+
if let photoURL = githubUser.avatarURL, let url = URL(string: photoURL) {
44+
let changeRequest = result.user.createProfileChangeRequest()
45+
changeRequest.photoURL = url
46+
changeRequest.displayName = githubUser.name ?? githubUser.login
47+
try await changeRequest.commitChanges()
48+
}
4949

50-
// 5. GitHub 계정과 Firebase Auth 계정 연결
51-
if !result.user.providerData.contains(where: { $0.providerID == "github.com" }) {
52-
let credential = OAuthProvider.credential(providerID: AuthProviderID.gitHub, accessToken: accessToken)
53-
try await result.user.link(with: credential)
54-
}
50+
// 5. GitHub 계정과 Firebase Auth 계정 연결
51+
if !result.user.providerData.contains(where: { $0.providerID == "github.com" }) {
52+
let credential = OAuthProvider.credential(providerID: AuthProviderID.gitHub, accessToken: accessToken)
53+
try await result.user.link(with: credential)
54+
}
5555

5656
let fcmToken = try await messaging.token()
5757

@@ -256,13 +256,13 @@ extension GithubAuthenticationService: ASWebAuthenticationPresentationContextPro
256256
struct GitHubUser: Codable {
257257
let login: String
258258
let name: String?
259-
let avatarUrl: String?
259+
let avatarURL: String?
260260
let email: String?
261261

262262
enum CodingKeys: String, CodingKey {
263263
case login
264264
case name
265-
case avatarUrl = "avatar_url"
265+
case avatarURL = "avatar_url"
266266
case email
267267
}
268268
}

Firebase/functions/package-lock.json

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Firebase/functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"axios": "^1.9.0",
1919
"dotenv": "^16.5.0",
2020
"firebase-admin": "^12.6.0",
21-
"firebase-functions": "^7.0.0",
21+
"firebase-functions": "^7.0.5",
2222
"jsonwebtoken": "^9.0.2"
2323
},
2424
"devDependencies": {

Firebase/functions/src/auth/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export const requestGithubTokens = onCall({
9090
// 4. Firebase Custom Token 생성
9191
const customToken = await admin.auth().createCustomToken(uid);
9292

93+
console.log(`GitHub 사용자(${userData.login})에 대한 커스텀 토큰이 생성되었습니다. UID: ${uid}`);
9394
return {
9495
accessToken,
9596
customToken

Firebase/functions/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as admin from "firebase-admin";
22
import * as dotenv from "dotenv";
3+
import * as path from "path";
34

45
// Apple 인증 관련 함수 가져오기
56
import {
@@ -33,7 +34,10 @@ import {
3334

3435

3536
// .env 파일 로드
36-
dotenv.config();
37+
dotenv.config({
38+
path: path.resolve(__dirname, "../.env"),
39+
override: true
40+
});
3741

3842
// Firebase 앱 초기화
3943
admin.initializeApp();

0 commit comments

Comments
 (0)