Skip to content

Commit

Permalink
Introduce PersonNameComponents for GoogleSignIn
Browse files Browse the repository at this point in the history
  • Loading branch information
EgzonArifi committed Nov 9, 2024
1 parent cb1cfb4 commit 967c8fd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
8 changes: 1 addition & 7 deletions Sources/Apple/AppleAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
41 changes: 41 additions & 0 deletions Sources/Core/PersonNameComponents+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 7 additions & 2 deletions Sources/Google/GoogleAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
5 changes: 4 additions & 1 deletion Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 967c8fd

Please sign in to comment.