diff --git a/Sources/Apple/AppleAuthenticator+Models.swift b/Sources/Apple/AppleAuthenticator+Models.swift index 935eb49..d09335d 100644 --- a/Sources/Apple/AppleAuthenticator+Models.swift +++ b/Sources/Apple/AppleAuthenticator+Models.swift @@ -25,13 +25,7 @@ public extension AppleAuthenticator { /// User full name represented by `givenName` and `familyName` public var name: String? { - guard let givenName = nameComponents?.givenName else { - return nameComponents?.familyName - } - guard let familyName = nameComponents?.familyName else { - return givenName - } - return "\(givenName) \(familyName)" + nameComponents?.name } } diff --git a/Sources/Core/PersonNameComponents+Extension.swift b/Sources/Core/PersonNameComponents+Extension.swift new file mode 100644 index 0000000..c07e459 --- /dev/null +++ b/Sources/Core/PersonNameComponents+Extension.swift @@ -0,0 +1,41 @@ +// +// PersonNameComponents+Extension.swift +// PovioKitAuth +// +// Created by Egzon Arifi on 09/11/2024. +// + +import AuthenticationServices +import Foundation + +public extension PersonNameComponents { + var name: String? { + guard let givenName = givenName else { + return familyName + } + guard let familyName = familyName else { + return givenName + } + return "\(givenName) \(familyName)" + } +} + +public extension PersonNameComponents { + static func create(namePrefix: String? = .none, + middleName: String? = .none, + givenName: String? = .none, + familyName: String? = .none, + nameSuffix: String? = .none, + nickname: String? = .none, + phoneticRepresentation: PersonNameComponents? = .none) -> PersonNameComponents { + var components = PersonNameComponents() + components.namePrefix = namePrefix + components.familyName = familyName + components.middleName = middleName + components.givenName = givenName + components.nameSuffix = nameSuffix + components.nickname = nickname + components.phoneticRepresentation = phoneticRepresentation + return components + } +} diff --git a/Sources/Google/GoogleAuthenticator+Models.swift b/Sources/Google/GoogleAuthenticator+Models.swift index a0906f6..3e433dd 100644 --- a/Sources/Google/GoogleAuthenticator+Models.swift +++ b/Sources/Google/GoogleAuthenticator+Models.swift @@ -7,15 +7,20 @@ // import Foundation +import PovioKitAuthCore public extension GoogleAuthenticator { - struct Response { public let userId: String? public let idToken: String? public let accessToken: String public let refreshToken: String - public let name: String? + public let nameComponents: PersonNameComponents? public let email: String? public let expiresAt: Date? + + /// User full name represented by `givenName` and `familyName` + public var name: String? { + nameComponents?.name + } } } diff --git a/Sources/Google/GoogleAuthenticator.swift b/Sources/Google/GoogleAuthenticator.swift index 6e7f88d..25db965 100644 --- a/Sources/Google/GoogleAuthenticator.swift +++ b/Sources/Google/GoogleAuthenticator.swift @@ -107,7 +107,10 @@ private extension GIDGoogleUser { idToken: idToken?.tokenString, accessToken: accessToken.tokenString, refreshToken: refreshToken.tokenString, - name: profile?.name, + nameComponents: PersonNameComponents.create( + givenName: profile?.givenName, + familyName: profile?.familyName + ), email: profile?.email, expiresAt: accessToken.expirationDate )