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

Feature/Introduce PersonNameComponents for Google, Facebook, LinkedIn sign in #33

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 17 additions & 20 deletions Sources/Core/PersonNameComponents+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,31 @@ import Foundation

public extension PersonNameComponents {
var name: String? {
guard let givenName = givenName else {
guard let givenName else {
return familyName
}
guard let familyName = familyName else {
guard let 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
init(namePrefix: String? = .none,
middleName: String? = .none,
givenName: String? = .none,
familyName: String? = .none,
nameSuffix: String? = .none,
nickname: String? = .none,
phoneticRepresentation: PersonNameComponents? = .none) {
yllfejziu marked this conversation as resolved.
Show resolved Hide resolved
self.init()
self.namePrefix = namePrefix
self.familyName = familyName
self.middleName = middleName
self.givenName = givenName
self.nameSuffix = nameSuffix
self.nickname = nickname
self.phoneticRepresentation = phoneticRepresentation
}
}
5 changes: 4 additions & 1 deletion Sources/Facebook/FacebookAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ private extension FacebookAuthenticator {
let authResponse = Response(
userId: object.id,
token: token.tokenString,
nameComponents: .create(givenName: object.firstName, familyName: object.lastName),
nameComponents: PersonNameComponents(
givenName: object.firstName,
familyName: object.lastName
),
email: object.email,
expiresAt: token.expirationDate
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private extension GIDGoogleUser {
idToken: idToken?.tokenString,
accessToken: accessToken.tokenString,
refreshToken: refreshToken.tokenString,
nameComponents: PersonNameComponents.create(
nameComponents: PersonNameComponents(
givenName: profile?.givenName,
familyName: profile?.familyName
),
Expand Down
5 changes: 4 additions & 1 deletion Sources/LinkedIn/LinkedInAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ extension LinkedInAuthenticator: Authenticator {
return Response(
userId: profileResponse.id,
token: authResponse.accessToken,
nameComponents: .create(givenName: profileResponse.localizedFirstName, familyName: profileResponse.localizedLastName),
nameComponents: PersonNameComponents(
givenName: profileResponse.localizedFirstName,
familyName: profileResponse.localizedLastName
),
email: emailResponse.emailAddress,
expiresAt: authResponse.expiresIn
)
Expand Down
Loading