Skip to content

Commit cc7207e

Browse files
authored
Fix database.useEmulator typing. (#4870)
* Fix database.useEmulator typing. * Create curly-lamps-rescue.md * Update packages/firebase/index.d.ts
1 parent 6e35e53 commit cc7207e

File tree

2 files changed

+91
-75
lines changed

2 files changed

+91
-75
lines changed

.changeset/curly-lamps-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"firebase": patch
3+
---
4+
5+
Fix database.useEmulator typing.

packages/firebase/index.d.ts

Lines changed: 86 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,81 @@ declare namespace firebase {
10061006
uid: string;
10071007
}
10081008

1009+
type FirebaseSignInProvider =
1010+
| 'custom'
1011+
| 'email'
1012+
| 'password'
1013+
| 'phone'
1014+
| 'anonymous'
1015+
| 'google.com'
1016+
| 'facebook.com'
1017+
| 'github.com'
1018+
| 'twitter.com'
1019+
| 'microsoft.com'
1020+
| 'apple.com';
1021+
1022+
interface FirebaseIdToken {
1023+
/** Always set to https://securetoken.google.com/PROJECT_ID */
1024+
iss: string;
1025+
1026+
/** Always set to PROJECT_ID */
1027+
aud: string;
1028+
1029+
/** The user's unique id */
1030+
sub: string;
1031+
1032+
/** The token issue time, in seconds since epoch */
1033+
iat: number;
1034+
1035+
/** The token expiry time, normally 'iat' + 3600 */
1036+
exp: number;
1037+
1038+
/** The user's unique id, must be equal to 'sub' */
1039+
user_id: string;
1040+
1041+
/** The time the user authenticated, normally 'iat' */
1042+
auth_time: number;
1043+
1044+
/** The sign in provider, only set when the provider is 'anonymous' */
1045+
provider_id?: 'anonymous';
1046+
1047+
/** The user's primary email */
1048+
email?: string;
1049+
1050+
/** The user's email verification status */
1051+
email_verified?: boolean;
1052+
1053+
/** The user's primary phone number */
1054+
phone_number?: string;
1055+
1056+
/** The user's display name */
1057+
name?: string;
1058+
1059+
/** The user's profile photo URL */
1060+
picture?: string;
1061+
1062+
/** Information on all identities linked to this user */
1063+
firebase: {
1064+
/** The primary sign-in provider */
1065+
sign_in_provider: FirebaseSignInProvider;
1066+
1067+
/** A map of providers to the user's list of unique identifiers from each provider */
1068+
identities?: { [provider in FirebaseSignInProvider]?: string[] };
1069+
};
1070+
1071+
/** Custom claims set by the developer */
1072+
[claim: string]: unknown;
1073+
1074+
// NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.)
1075+
uid?: never;
1076+
}
1077+
1078+
export type EmulatorMockTokenOptions = (
1079+
| { user_id: string }
1080+
| { sub: string }
1081+
) &
1082+
Partial<FirebaseIdToken>;
1083+
10091084
/**
10101085
* Retrieves a Firebase {@link firebase.app.App app} instance.
10111086
*
@@ -5738,8 +5813,15 @@ declare namespace firebase.database {
57385813
*
57395814
* @param host the emulator host (ex: localhost)
57405815
* @param port the emulator port (ex: 8080)
5816+
* @param options.mockUserToken the mock auth token to use for unit testing Security Rules
57415817
*/
5742-
useEmulator(host: string, port: number): void;
5818+
useEmulator(
5819+
host: string,
5820+
port: number,
5821+
options?: {
5822+
mockUserToken?: EmulatorMockTokenOptions;
5823+
}
5824+
): void;
57435825
/**
57445826
* Disconnects from the server (all Database operations will be completed
57455827
* offline).
@@ -7081,6 +7163,8 @@ declare namespace firebase.database {
70817163
logger?: boolean | ((a: string) => any),
70827164
persistent?: boolean
70837165
): any;
7166+
7167+
export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
70847168
}
70857169

70867170
declare namespace firebase.database.ServerValue {
@@ -10012,80 +10096,7 @@ declare namespace firebase.firestore {
1001210096
stack?: string;
1001310097
}
1001410098

10015-
type FirebaseSignInProvider =
10016-
| 'custom'
10017-
| 'email'
10018-
| 'password'
10019-
| 'phone'
10020-
| 'anonymous'
10021-
| 'google.com'
10022-
| 'facebook.com'
10023-
| 'github.com'
10024-
| 'twitter.com'
10025-
| 'microsoft.com'
10026-
| 'apple.com';
10027-
10028-
interface FirebaseIdToken {
10029-
/** Always set to https://securetoken.google.com/PROJECT_ID */
10030-
iss: string;
10031-
10032-
/** Always set to PROJECT_ID */
10033-
aud: string;
10034-
10035-
/** The user's unique id */
10036-
sub: string;
10037-
10038-
/** The token issue time, in seconds since epoch */
10039-
iat: number;
10040-
10041-
/** The token expiry time, normally 'iat' + 3600 */
10042-
exp: number;
10043-
10044-
/** The user's unique id, must be equal to 'sub' */
10045-
user_id: string;
10046-
10047-
/** The time the user authenticated, normally 'iat' */
10048-
auth_time: number;
10049-
10050-
/** The sign in provider, only set when the provider is 'anonymous' */
10051-
provider_id?: 'anonymous';
10052-
10053-
/** The user's primary email */
10054-
email?: string;
10055-
10056-
/** The user's email verification status */
10057-
email_verified?: boolean;
10058-
10059-
/** The user's primary phone number */
10060-
phone_number?: string;
10061-
10062-
/** The user's display name */
10063-
name?: string;
10064-
10065-
/** The user's profile photo URL */
10066-
picture?: string;
10067-
10068-
/** Information on all identities linked to this user */
10069-
firebase: {
10070-
/** The primary sign-in provider */
10071-
sign_in_provider: FirebaseSignInProvider;
10072-
10073-
/** A map of providers to the user's list of unique identifiers from each provider */
10074-
identities?: { [provider in FirebaseSignInProvider]?: string[] };
10075-
};
10076-
10077-
/** Custom claims set by the developer */
10078-
[claim: string]: unknown;
10079-
10080-
// NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.)
10081-
uid?: never;
10082-
}
10083-
10084-
export type EmulatorMockTokenOptions = (
10085-
| { user_id: string }
10086-
| { sub: string }
10087-
) &
10088-
Partial<FirebaseIdToken>;
10099+
export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
1008910100
}
1009010101

1009110102
export default firebase;

0 commit comments

Comments
 (0)