Skip to content

Commit 6de08e1

Browse files
committed
fix(auth): userinfo return for fromNative
feat: toJSON user info
1 parent 3986346 commit 6de08e1

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

packages/firebase-auth/index.android.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ export class UserMetadata implements IUserMetadata {
7373
}
7474
return null;
7575
}
76+
77+
toJSON() {
78+
return {
79+
creationDate: this.creationDate,
80+
lastSignInDate: this.lastSignInDate
81+
}
82+
}
7683
}
7784

7885
export class UserInfo implements IUserInfo {
@@ -82,6 +89,7 @@ export class UserInfo implements IUserInfo {
8289
if (info) {
8390
const nativeInfo = new UserInfo();
8491
nativeInfo.#native = info;
92+
return nativeInfo;
8593
}
8694
return null;
8795
}
@@ -122,6 +130,17 @@ export class UserInfo implements IUserInfo {
122130
get providerId(): string {
123131
return this.native?.getProviderId?.();
124132
}
133+
134+
toJSON() {
135+
return {
136+
displayName: this.displayName,
137+
email: this.email,
138+
uid: this.uid,
139+
phoneNumber: this.phoneNumber,
140+
providerId: this.providerId,
141+
photoURL: this.photoURL,
142+
}
143+
}
125144
}
126145

127146
export class User implements IUser {
@@ -194,6 +213,21 @@ export class User implements IUser {
194213
return data;
195214
}
196215

216+
toJSON() {
217+
return {
218+
displayName: this.displayName,
219+
anonymous: this.anonymous,
220+
emailVerified: this.emailVerified,
221+
email: this.email,
222+
uid: this.uid,
223+
phoneNumber: this.phoneNumber,
224+
providerId: this.providerId,
225+
photoURL: this.photoURL,
226+
metadata: this.metadata,
227+
providerData: this.providerData
228+
}
229+
}
230+
197231
delete(): Promise<void> {
198232
return new Promise((resolve, reject) => {
199233
if (!this.native) {
@@ -741,9 +775,9 @@ export class PhoneAuthProvider {
741775
ensureClass();
742776
const cb = new OnVerificationStateChangedCallbacks(resolve, reject);
743777
com.google.firebase.auth.PhoneAuthProvider
744-
.verifyPhoneNumber(this.native.setPhoneNumber(phoneNumber)
745-
.setCallbacks(cb)
746-
.build());
778+
.verifyPhoneNumber(this.native.setPhoneNumber(phoneNumber)
779+
.setCallbacks(cb)
780+
.build());
747781
}
748782
});
749783
}
@@ -806,8 +840,6 @@ export class OAuthCredential extends AuthCredential implements IOAuthCredential
806840
}
807841
}
808842

809-
810-
811843
export class OAuthProvider implements IOAuthProvider {
812844
#providerId: string;
813845
#customProvider: boolean;

packages/firebase-auth/index.ios.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export class UserMetadata implements IUserMetadata {
4848
get lastSignInDate(): Date {
4949
return this.native.lastSignInDate;
5050
}
51+
52+
toJSON() {
53+
return {
54+
creationDate: this.creationDate,
55+
lastSignInDate: this.lastSignInDate
56+
}
57+
}
5158
}
5259

5360
export class UserInfo implements IUserInfo {
@@ -57,6 +64,7 @@ export class UserInfo implements IUserInfo {
5764
if (info) {
5865
const nativeInfo = new UserInfo();
5966
nativeInfo.#native = info;
67+
return nativeInfo;
6068
}
6169
return null;
6270
}
@@ -92,6 +100,17 @@ export class UserInfo implements IUserInfo {
92100
get providerId(): string {
93101
return this.native?.providerID;
94102
}
103+
104+
toJSON() {
105+
return {
106+
displayName: this.displayName,
107+
email: this.email,
108+
uid: this.uid,
109+
phoneNumber: this.phoneNumber,
110+
providerId: this.providerId,
111+
photoURL: this.photoURL,
112+
}
113+
}
95114
}
96115

97116
export class User implements IUser {
@@ -159,6 +178,21 @@ export class User implements IUser {
159178
return data;
160179
}
161180

181+
toJSON() {
182+
return {
183+
displayName: this.displayName,
184+
anonymous: this.anonymous,
185+
emailVerified: this.emailVerified,
186+
email: this.email,
187+
uid: this.uid,
188+
phoneNumber: this.phoneNumber,
189+
providerId: this.providerId,
190+
photoURL: this.photoURL,
191+
metadata: this.metadata,
192+
providerData: this.providerData
193+
}
194+
}
195+
162196
delete(): Promise<void> {
163197
return new Promise((resolve, reject) => {
164198
if (!this.native) {

0 commit comments

Comments
 (0)