Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로그인 - FCM 기능 추가 #277

Merged
merged 3 commits into from
Apr 11, 2023
Merged
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
23 changes: 23 additions & 0 deletions PLUB/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import GoogleSignIn
import KakaoSDKCommon
import FirebaseCore
import FirebaseMessaging

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -24,6 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
)

FirebaseApp.configure()
configureCloudMessaging(application)

setupNavigationBarStyle()

Expand All @@ -39,6 +41,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}

// MARK: Configuration Methods

private func configureCloudMessaging(_ application: UIApplication) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in

}

application.registerForRemoteNotifications()

Messaging.messaging().delegate = self
}

private func setupNavigationBarStyle() {
let appearance = UINavigationBarAppearance()

Expand All @@ -60,3 +74,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

// MARK: - MessagingDelegate

extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let fcmToken else { return }
Log.notice(fcmToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

UserManager.shared.set(fcmToken: fcmToken)
}
}
9 changes: 9 additions & 0 deletions PLUB/Configuration/Manager/UserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ final class UserManager {
@KeyChainWrapper<String>(key: "refreshToken")
private(set) var refreshToken

@KeyChainWrapper<String>(key: "fcmToken")
private(set) var fcmToken

// MARK: - Social Login Type

@UserDefaultsWrapper<SocialType>(key: "socialType")
Expand Down Expand Up @@ -61,6 +64,11 @@ extension UserManager {
self.signToken = signToken
}

/// 플럽 푸시 알림에 필요한 `firebase cloud messaging Token`을 세팅합니다.
func set(fcmToken: String) {
self.fcmToken = fcmToken
}

/// 소셜로그인 타입을 세팅합니다.
/// - Parameter socialType: 소셜로그인 타입(애플, 구글, 카카오)
func set(socialType: SocialType) {
Expand All @@ -77,6 +85,7 @@ extension UserManager {
accessToken = nil
refreshToken = nil
signToken = nil
fcmToken = nil
socialType = nil
}

Expand Down
3 changes: 3 additions & 0 deletions PLUB/Sources/Models/Auth/Request/SignInRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Foundation
/// 소셜 로그인 요청 모델
struct SignInRequest: Codable {

/// Firebase Cloud Messaging Token
let fcmToken: String

/// 액세스 토큰(카카오, 애플)
/// 애플의 경우 identityToken을 해당 값으로 처리해야합니다.
let accessToken: String?
Expand Down
6 changes: 6 additions & 0 deletions PLUB/Sources/Models/Auth/Request/SignUpRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Then

/// 회원가입 요청 모델
struct SignUpRequest: Codable {

/// Firebase Cloud Messaging Token
let fcmToken: String

/// sign token
var signToken: String

Expand Down Expand Up @@ -48,6 +52,7 @@ struct SignUpRequest: Codable {
var marketing: Bool

init() {
fcmToken = UserManager.shared.fcmToken!
signToken = UserManager.shared.signToken!
categoryList = []
birthday = ""
Expand All @@ -66,6 +71,7 @@ struct SignUpRequest: Codable {

extension SignUpRequest {
enum CodingKeys: String, CodingKey {
case fcmToken
case signToken
case categoryList
case profileImageLink = "profileImage"
Expand Down
9 changes: 8 additions & 1 deletion PLUB/Sources/Network/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ extension AuthService {
authorizationCode: String?
) -> PLUBResult<SignInResponse> {
return sendRequest(
AuthRouter.socialLogin(SignInRequest(accessToken: token, authorizationCode: authorizationCode, socialType: socialType)),
AuthRouter.socialLogin(
SignInRequest(
fcmToken: UserManager.shared.fcmToken!,
accessToken: token,
authorizationCode: authorizationCode,
socialType: socialType
)
),
type: SignInResponse.self
)
}
Expand Down