Skip to content

Commit

Permalink
아직도 애플로그인..;
Browse files Browse the repository at this point in the history
  • Loading branch information
doyeonk429 committed Nov 21, 2024
1 parent 432076e commit 316a006
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions DropDrug/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")
SelectLoginTypeVC.keychain.set(fcmToken!, forKey: "FCMToken")
// print(SelectLoginTypeVC.keychain.get("appleUserFullName") ?? "저장된 이름 없음")

let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
Expand Down
24 changes: 24 additions & 0 deletions DropDrug/Sources/ViewControllers/EnrollDetailViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2024 RT4. All rights reserved

import UIKit

class EnrollDetailViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/

}
45 changes: 32 additions & 13 deletions DropDrug/Sources/ViewControllers/Register/SelectLoginTypeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,32 +326,51 @@ extension SelectLoginTypeVC : ASAuthorizationControllerDelegate {
print("Error: Nonce is missing.")
return
}

guard let appleIDToken = appleIDCredential.identityToken else {
print("Error: Unable to fetch identity token.")
return
}

guard let idTokenString = String(data: appleIDToken, encoding: .utf8) else {
print("Error: Unable to serialize token string.")
return
}
SelectLoginTypeVC.keychain.set(idTokenString, forKey: "appleUserIDToken")

var fullNameToUse: PersonNameComponents? = nil

guard let fullName = appleIDCredential.fullName else {
print("Unable to fetch full name")
return
if let fullName = appleIDCredential.fullName {
fullNameToUse = fullName
if let givenName = fullName.givenName, let familyName = fullName.familyName {
let completeName = "\(givenName) \(familyName)"
SelectLoginTypeVC.keychain.set(completeName, forKey: "appleUserFullName")
print("Saved fullName: \(completeName)")
}
}
SelectLoginTypeVC.keychain.set(appleIDToken, forKey: "appleUserIDToken")

if let givenName = fullName.givenName, let familyName = fullName.familyName {
let completeName = "\(givenName) \(familyName)"
SelectLoginTypeVC.keychain.set(completeName, forKey: "appleUserfullName")
print("Saved fullName: \(completeName)")
} else {
print("No full name provided.")
if let savedFullName = SelectLoginTypeVC.keychain.get("appleUserFullName") {
print("무조건 진입아님?\(SelectLoginTypeVC.keychain.get("appleUserFullName"))")

var nameComponents = PersonNameComponents()
let nameParts = savedFullName.split(separator: " ")
if nameParts.count > 1 {
nameComponents.givenName = String(nameParts[0])
nameComponents.familyName = String(nameParts[1])
} else {
nameComponents.givenName = savedFullName
}
fullNameToUse = nameComponents
print("Fetched saved fullName from Keychain: \(savedFullName)")
}

print("idTokenString : \(idTokenString)")

let credential = OAuthProvider.appleCredential(withIDToken: idTokenString, rawNonce: nonce, fullName: fullName)
print("idTokenString")
print(idTokenString)
print("nonce")
print(nonce)
print(fullNameToUse ?? "nil")

let credential = OAuthProvider.appleCredential(withIDToken: idTokenString, rawNonce: nonce, fullName: fullNameToUse!)

Auth.auth().signIn(with: credential) { authResult, error in
if let error = error {
Expand Down

0 comments on commit 316a006

Please sign in to comment.