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

feat(ios): make all permitted user profile fields available when using limited login #582

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions ios/RCTFBSDK/core/RCTFBSDKProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ - (dispatch_queue_t)methodQueue
@"linkURL": FBSDKProfile.currentProfile.linkURL ? FBSDKProfile.currentProfile.linkURL.relativeString : [NSNull null],
@"userID": FBSDKProfile.currentProfile.userID ? FBSDKProfile.currentProfile.userID : [NSNull null],
@"email": FBSDKProfile.currentProfile.email ? FBSDKProfile.currentProfile.email : [NSNull null],
@"refreshDate": FBSDKProfile.currentProfile.refreshDate ? @(FBSDKProfile.currentProfile.refreshDate.timeIntervalSince1970 * 1000) : [NSNull null],
@"friendIDs": FBSDKProfile.currentProfile.friendIDs ? FBSDKProfile.currentProfile.friendIDs : [NSNull null],
@"birthday": FBSDKProfile.currentProfile.birthday ? @(FBSDKProfile.currentProfile.birthday.timeIntervalSince1970 * 1000) : [NSNull null],
@"ageRange": FBSDKProfile.currentProfile.ageRange ? @{
@"min": FBSDKProfile.currentProfile.ageRange.min,
@"max": FBSDKProfile.currentProfile.ageRange.max
} : [NSNull null],
@"hometown": FBSDKProfile.currentProfile.hometown ? @{
@"id": FBSDKProfile.currentProfile.hometown.id,
@"name": FBSDKProfile.currentProfile.hometown.name
} : [NSNull null],
@"location": FBSDKProfile.currentProfile.location ? @{
@"id": FBSDKProfile.currentProfile.location.id,
@"name": FBSDKProfile.currentProfile.location.name
} : [NSNull null],
@"gender": FBSDKProfile.currentProfile.gender ? FBSDKProfile.currentProfile.gender : [NSNull null],
@"permissions": FBSDKProfile.currentProfile.permissions ? FBSDKProfile.currentProfile.permissions.allObjects : [NSNull null]
};
}

Expand Down
70 changes: 69 additions & 1 deletion src/FBProfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @format
*/
import {Platform, NativeModules} from 'react-native';
import { Platform, NativeModules } from 'react-native';

const Profile = NativeModules.FBProfile;

Expand All @@ -14,6 +14,14 @@ export type ProfileMap = {
userID?: string | null;
email?: string | null;
name?: string | null;
refreshDate?: number | null,
friendIDs?: Array<string> | null,
birthday?: number | null,
ageRange?: { min: number, max: number } | null,
hometown?: { id: string, name: string } | null,
location?: { id: string, name: string } | null,
gender?: string | null,
permissions?: Array<string> | null
};

/**
Expand Down Expand Up @@ -63,6 +71,58 @@ class FBProfile {
*/
imageURL?: string | null;

/**
* The last time the profile data was fetched.
*/
refreshDate?: Date | null;

/**
* A list of identifiers of the user’s friends.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_friends' permission and
* limited login flow is used on iOS
*/
friendIDs?: Array<string> | null;

/**
* The user’s birthday.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_birthday' permission and
* limited login flow is used on iOS
*/
birthday?: Date | null;

/**
* The user’s age range.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_age_range' permission and
* limited login flow is used on iOS
*/
ageRange?: { min: number, max: number } | null;

/**
* The user’s hometown.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_hometown' permission and
* limited login flow is used on iOS
*/
hometown?: { id: string, name: string } | null;

/**
* The user’s location.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_location' permission and
* limited login flow is used on iOS
*/
location?: { id: string, name: string } | null;

/**
* The user’s gender.
* IMPORTANT: This field will only be populated if your user has granted your application the 'user_gender' permission and
* limited login flow is used on iOS
*/
gender?: string | null;

/**
* The user’s granted permissions.
*/
permissions?: Array<string> | null;

constructor(profileMap: ProfileMap) {
this.firstName = profileMap.firstName;
this.lastName = profileMap.lastName;
Expand All @@ -74,6 +134,14 @@ class FBProfile {
this.email = profileMap.email;
}
this.name = profileMap.name;
this.refreshDate = profileMap.refreshDate ? new Date(profileMap.refreshDate) : null;
this.friendIDs = profileMap.friendIDs;
this.birthday = profileMap.birthday ? new Date(profileMap.birthday) : null;
this.ageRange = profileMap.ageRange;
this.hometown = profileMap.hometown;
this.location = profileMap.location;
this.gender = profileMap.gender;
this.permissions = profileMap.permissions;
Object.freeze(this);
}

Expand Down
Loading