UNPKG

14.6 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
19import { Observer, Unsubscribe } from '@firebase/util';
20
21export interface User extends UserInfo {
22 delete(): Promise<void>;
23 emailVerified: boolean;
24 getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
25 getIdToken(forceRefresh?: boolean): Promise<string>;
26 isAnonymous: boolean;
27 linkAndRetrieveDataWithCredential(
28 credential: AuthCredential
29 ): Promise<UserCredential>;
30 linkWithCredential(credential: AuthCredential): Promise<UserCredential>;
31 linkWithPhoneNumber(
32 phoneNumber: string,
33 applicationVerifier: ApplicationVerifier
34 ): Promise<ConfirmationResult>;
35 linkWithPopup(provider: AuthProvider): Promise<UserCredential>;
36 linkWithRedirect(provider: AuthProvider): Promise<void>;
37 metadata: UserMetadata;
38 multiFactor: MultiFactorUser;
39 phoneNumber: string | null;
40 providerData: (UserInfo | null)[];
41 reauthenticateAndRetrieveDataWithCredential(
42 credential: AuthCredential
43 ): Promise<UserCredential>;
44 reauthenticateWithCredential(
45 credential: AuthCredential
46 ): Promise<UserCredential>;
47 reauthenticateWithPhoneNumber(
48 phoneNumber: string,
49 applicationVerifier: ApplicationVerifier
50 ): Promise<ConfirmationResult>;
51 reauthenticateWithPopup(provider: AuthProvider): Promise<UserCredential>;
52 reauthenticateWithRedirect(provider: AuthProvider): Promise<void>;
53 refreshToken: string;
54 reload(): Promise<void>;
55 sendEmailVerification(
56 actionCodeSettings?: ActionCodeSettings | null
57 ): Promise<void>;
58 readonly tenantId: string | null;
59 toJSON(): Object;
60 unlink(providerId: string): Promise<User>;
61 updateEmail(newEmail: string): Promise<void>;
62 updatePassword(newPassword: string): Promise<void>;
63 updatePhoneNumber(phoneCredential: AuthCredential): Promise<void>;
64 updateProfile(profile: {
65 displayName?: string | null;
66 photoURL?: string | null;
67 }): Promise<void>;
68 verifyBeforeUpdateEmail(
69 newEmail: string,
70 actionCodeSettings?: ActionCodeSettings | null
71 ): Promise<void>;
72}
73
74export interface UserInfo {
75 displayName: string | null;
76 email: string | null;
77 phoneNumber: string | null;
78 photoURL: string | null;
79 providerId: string;
80 uid: string;
81}
82
83export interface MultiFactorUser {
84 enrolledFactors: MultiFactorInfo[];
85 enroll(
86 assertion: MultiFactorAssertion,
87 displayName?: string | null
88 ): Promise<void>;
89 getSession(): Promise<MultiFactorSession>;
90 unenroll(option: MultiFactorInfo | string): Promise<void>;
91}
92
93export class ActionCodeInfo {
94 private constructor();
95 data: {
96 email?: string | null;
97 fromEmail?: string | null;
98 multiFactorInfo?: MultiFactorInfo | null;
99 previousEmail?: string | null;
100 };
101 operation: string;
102 static Operation: {
103 PASSWORD_RESET: Operation;
104 RECOVER_EMAIL: Operation;
105 EMAIL_SIGNIN: Operation;
106 REVERT_SECOND_FACTOR_ADDITION: Operation;
107 VERIFY_AND_CHANGE_EMAIL: Operation;
108 VERIFY_EMAIL: Operation;
109 };
110}
111
112export class ActionCodeURL {
113 private constructor();
114 apiKey: string;
115 code: string;
116 continueUrl: string | null;
117 languageCode: string | null;
118 operation: Operation;
119 static parseLink(link: string): ActionCodeURL | null;
120 tenantId: string | null;
121}
122
123export type ActionCodeSettings = {
124 android?: {
125 installApp?: boolean;
126 minimumVersion?: string;
127 packageName: string;
128 };
129 handleCodeInApp?: boolean;
130 iOS?: { bundleId: string };
131 url: string;
132 dynamicLinkDomain?: string;
133};
134
135export type AdditionalUserInfo = {
136 isNewUser: boolean;
137 profile: Object | null;
138 providerId: string | null;
139 username?: string | null;
140};
141
142export interface ApplicationVerifier {
143 type: string;
144 verify(): Promise<string>;
145}
146
147export abstract class AuthCredential {
148 providerId: string;
149 signInMethod: string;
150 toJSON(): Object;
151 static fromJSON(json: Object | string): AuthCredential | null;
152}
153
154export interface AuthProvider {
155 providerId: string;
156}
157
158export interface ConfirmationResult {
159 confirm(verificationCode: string): Promise<UserCredential>;
160 verificationId: string;
161}
162
163export class EmailAuthProvider extends EmailAuthProvider_Instance {
164 static PROVIDER_ID: string;
165 static EMAIL_PASSWORD_SIGN_IN_METHOD: string;
166 static EMAIL_LINK_SIGN_IN_METHOD: string;
167 static credential(email: string, password: string): AuthCredential;
168 static credentialWithLink(email: string, emailLink: string): AuthCredential;
169}
170export class EmailAuthProvider_Instance implements AuthProvider {
171 providerId: string;
172}
173
174export interface Error {
175 code: string;
176 name: string;
177 message: string;
178 stack?: string;
179}
180
181export interface AuthError extends Error {
182 credential?: AuthCredential;
183 email?: string;
184 phoneNumber?: string;
185 tenantId?: string;
186}
187
188export interface MultiFactorError extends AuthError {
189 resolver: MultiFactorResolver;
190}
191
192export class FacebookAuthProvider extends FacebookAuthProvider_Instance {
193 static PROVIDER_ID: string;
194 static FACEBOOK_SIGN_IN_METHOD: string;
195 static credential(token: string): AuthCredential;
196}
197export class FacebookAuthProvider_Instance implements AuthProvider {
198 addScope(scope: string): AuthProvider;
199 providerId: string;
200 setCustomParameters(customOAuthParameters: Object): AuthProvider;
201}
202
203export class GithubAuthProvider extends GithubAuthProvider_Instance {
204 static PROVIDER_ID: string;
205 static GITHUB_SIGN_IN_METHOD: string;
206 static credential(token: string): AuthCredential;
207}
208export class GithubAuthProvider_Instance implements AuthProvider {
209 addScope(scope: string): AuthProvider;
210 providerId: string;
211 setCustomParameters(customOAuthParameters: Object): AuthProvider;
212}
213
214export class GoogleAuthProvider extends GoogleAuthProvider_Instance {
215 static PROVIDER_ID: string;
216 static GOOGLE_SIGN_IN_METHOD: string;
217 static credential(
218 idToken?: string | null,
219 accessToken?: string | null
220 ): AuthCredential;
221}
222export class GoogleAuthProvider_Instance implements AuthProvider {
223 addScope(scope: string): AuthProvider;
224 providerId: string;
225 setCustomParameters(customOAuthParameters: Object): AuthProvider;
226}
227
228export interface IdTokenResult {
229 token: string;
230 expirationTime: string;
231 authTime: string;
232 issuedAtTime: string;
233 signInProvider: string | null;
234 signInSecondFactor: string | null;
235 claims: {
236 [key: string]: any;
237 };
238}
239
240export class OAuthProvider implements AuthProvider {
241 constructor(providerId: string);
242 providerId: string;
243 addScope(scope: string): AuthProvider;
244 credential(
245 optionsOrIdToken: OAuthCredentialOptions | string | null,
246 accessToken?: string
247 ): OAuthCredential;
248 setCustomParameters(customOAuthParameters: Object): AuthProvider;
249}
250
251export class SAMLAuthProvider implements AuthProvider {
252 constructor(providerId: string);
253 providerId: string;
254}
255
256export class PhoneAuthProvider extends PhoneAuthProvider_Instance {
257 static PROVIDER_ID: string;
258 static PHONE_SIGN_IN_METHOD: string;
259 static credential(
260 verificationId: string,
261 verificationCode: string
262 ): AuthCredential;
263}
264export class PhoneAuthProvider_Instance implements AuthProvider {
265 constructor(auth?: FirebaseAuth | null);
266 providerId: string;
267 verifyPhoneNumber(
268 phoneInfoOptions: PhoneInfoOptions | string,
269 applicationVerifier: ApplicationVerifier
270 ): Promise<string>;
271}
272
273export type PhoneInfoOptions =
274 | PhoneSingleFactorInfoOptions
275 | PhoneMultiFactorEnrollInfoOptions
276 | PhoneMultiFactorSignInInfoOptions;
277
278export interface PhoneSingleFactorInfoOptions {
279 phoneNumber: string;
280}
281
282export interface PhoneMultiFactorEnrollInfoOptions {
283 phoneNumber: string;
284 session: MultiFactorSession;
285}
286
287export interface PhoneMultiFactorSignInInfoOptions {
288 multiFactorHint?: MultiFactorInfo;
289 multiFactorUid?: string;
290 session: MultiFactorSession;
291}
292
293export class RecaptchaVerifier extends RecaptchaVerifier_Instance {}
294export class RecaptchaVerifier_Instance implements ApplicationVerifier {
295 constructor(
296 container: any | string,
297 parameters?: Object | null,
298 app?: FirebaseApp | null
299 );
300 clear(): void;
301 render(): Promise<number>;
302 type: string;
303 verify(): Promise<string>;
304}
305
306export class TwitterAuthProvider extends TwitterAuthProvider_Instance {
307 static PROVIDER_ID: string;
308 static TWITTER_SIGN_IN_METHOD: string;
309 static credential(token: string, secret: string): AuthCredential;
310}
311export class TwitterAuthProvider_Instance implements AuthProvider {
312 providerId: string;
313 setCustomParameters(customOAuthParameters: Object): AuthProvider;
314}
315
316export type UserCredential = {
317 additionalUserInfo?: AdditionalUserInfo | null;
318 credential: AuthCredential | null;
319 operationType?: string | null;
320 user: User | null;
321};
322
323export interface UserMetadata {
324 creationTime?: string;
325 lastSignInTime?: string;
326}
327
328export type Persistence = string;
329
330export type Operation = string;
331
332export class OAuthCredential extends AuthCredential {
333 private constructor();
334 idToken?: string;
335 accessToken?: string;
336 secret?: string;
337}
338
339export interface OAuthCredentialOptions {
340 idToken?: string;
341 accessToken?: string;
342 rawNonce?: string;
343}
344
345export class PhoneAuthCredential extends AuthCredential {
346 private constructor();
347}
348
349export interface AuthSettings {
350 appVerificationDisabledForTesting: boolean;
351}
352
353export class MultiFactorSession {
354 private constructor();
355}
356
357export abstract class MultiFactorAssertion {
358 factorId: string;
359}
360
361export class MultiFactorResolver {
362 private constructor();
363 auth: FirebaseAuth;
364 session: MultiFactorSession;
365 hints: MultiFactorInfo[];
366 resolveSignIn(assertion: MultiFactorAssertion): Promise<UserCredential>;
367}
368
369export interface MultiFactorInfo {
370 uid: string;
371 displayName?: string | null;
372 enrollmentTime: string;
373 factorId: string;
374}
375
376export interface PhoneMultiFactorInfo extends MultiFactorInfo {
377 phoneNumber: string;
378}
379
380export class PhoneMultiFactorAssertion extends MultiFactorAssertion {
381 private constructor();
382}
383
384export class PhoneMultiFactorGenerator {
385 private constructor();
386 static FACTOR_ID: string;
387 static assertion(
388 phoneAuthCredential: PhoneAuthCredential
389 ): PhoneMultiFactorAssertion;
390}
391
392export interface EmulatorConfig {
393 readonly protocol: string;
394 readonly host: string;
395 readonly port: number | null;
396 readonly options: {
397 readonly disableWarnings: boolean;
398 };
399}
400
401export class FirebaseAuth {
402 private constructor();
403
404 static Persistence: {
405 LOCAL: Persistence;
406 NONE: Persistence;
407 SESSION: Persistence;
408 };
409
410 app: FirebaseApp;
411 applyActionCode(code: string): Promise<void>;
412 checkActionCode(code: string): Promise<ActionCodeInfo>;
413 confirmPasswordReset(code: string, newPassword: string): Promise<void>;
414 createUserWithEmailAndPassword(
415 email: string,
416 password: string
417 ): Promise<UserCredential>;
418 currentUser: User | null;
419 readonly emulatorConfig: EmulatorConfig | null;
420 fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;
421 isSignInWithEmailLink(emailLink: string): boolean;
422 getRedirectResult(): Promise<UserCredential>;
423 languageCode: string | null;
424 settings: AuthSettings;
425 onAuthStateChanged(
426 nextOrObserver: Observer<any> | ((a: User | null) => any),
427 error?: (a: Error) => any,
428 completed?: Unsubscribe
429 ): Unsubscribe;
430 onIdTokenChanged(
431 nextOrObserver: Observer<any> | ((a: User | null) => any),
432 error?: (a: Error) => any,
433 completed?: Unsubscribe
434 ): Unsubscribe;
435 sendSignInLinkToEmail(
436 email: string,
437 actionCodeSettings: ActionCodeSettings
438 ): Promise<void>;
439 sendPasswordResetEmail(
440 email: string,
441 actionCodeSettings?: ActionCodeSettings | null
442 ): Promise<void>;
443 setPersistence(persistence: Persistence): Promise<void>;
444 signInAndRetrieveDataWithCredential(
445 credential: AuthCredential
446 ): Promise<UserCredential>;
447 signInAnonymously(): Promise<UserCredential>;
448 signInWithCredential(credential: AuthCredential): Promise<UserCredential>;
449 signInWithCustomToken(token: string): Promise<UserCredential>;
450 signInWithEmailAndPassword(
451 email: string,
452 password: string
453 ): Promise<UserCredential>;
454 signInWithEmailLink(
455 email: string,
456 emailLink?: string
457 ): Promise<UserCredential>;
458 signInWithPhoneNumber(
459 phoneNumber: string,
460 applicationVerifier: ApplicationVerifier
461 ): Promise<ConfirmationResult>;
462 signInWithPopup(provider: AuthProvider): Promise<UserCredential>;
463 signInWithRedirect(provider: AuthProvider): Promise<void>;
464 signOut(): Promise<void>;
465 tenantId: string | null;
466 updateCurrentUser(user: User | null): Promise<void>;
467 useDeviceLanguage(): void;
468 useEmulator(url: string, options?: { disableWarnings?: boolean }): void;
469 verifyPasswordResetCode(code: string): Promise<string>;
470}
471
472declare module '@firebase/app-types' {
473 interface FirebaseNamespace {
474 auth?: {
475 (app?: FirebaseApp): FirebaseAuth;
476 Auth: typeof FirebaseAuth;
477 EmailAuthProvider: typeof EmailAuthProvider;
478 EmailAuthProvider_Instance: typeof EmailAuthProvider_Instance;
479 FacebookAuthProvider: typeof FacebookAuthProvider;
480 FacebookAuthProvider_Instance: typeof FacebookAuthProvider_Instance;
481 GithubAuthProvider: typeof GithubAuthProvider;
482 GithubAuthProvider_Instance: typeof GithubAuthProvider_Instance;
483 GoogleAuthProvider: typeof GoogleAuthProvider;
484 GoogleAuthProvider_Instance: typeof GoogleAuthProvider_Instance;
485 OAuthProvider: typeof OAuthProvider;
486 SAMLAuthProvider: typeof SAMLAuthProvider;
487 PhoneAuthProvider: typeof PhoneAuthProvider;
488 PhoneAuthProvider_Instance: typeof PhoneAuthProvider_Instance;
489 PhoneMultiFactorGenerator: typeof PhoneMultiFactorGenerator;
490 RecaptchaVerifier: typeof RecaptchaVerifier;
491 RecaptchaVerifier_Instance: typeof RecaptchaVerifier_Instance;
492 TwitterAuthProvider: typeof TwitterAuthProvider;
493 TwitterAuthProvider_Instance: typeof TwitterAuthProvider_Instance;
494 };
495 }
496 interface FirebaseApp {
497 auth?(): FirebaseAuth;
498 }
499}
500
501declare module '@firebase/component' {
502 interface NameServiceMapping {
503 'auth-compat': FirebaseAuth;
504 }
505}