UNPKG

3.44 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 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 */
17import { Auth, AuthProvider, Persistence, PopupRedirectResolver, UserCredential } from './public_types';
18import { FirebaseError } from '@firebase/util';
19import { AuthPopup } from '../platform_browser/util/popup';
20import { AuthInternal } from './auth';
21import { UserCredentialInternal } from './user';
22export declare const enum EventFilter {
23 POPUP = 0,
24 REDIRECT = 1
25}
26export declare const enum GapiOutcome {
27 ACK = "ACK",
28 ERROR = "ERROR"
29}
30export interface GapiAuthEvent extends gapi.iframes.Message {
31 authEvent: AuthEvent;
32}
33/**
34 * @internal
35 */
36export declare const enum AuthEventType {
37 LINK_VIA_POPUP = "linkViaPopup",
38 LINK_VIA_REDIRECT = "linkViaRedirect",
39 REAUTH_VIA_POPUP = "reauthViaPopup",
40 REAUTH_VIA_REDIRECT = "reauthViaRedirect",
41 SIGN_IN_VIA_POPUP = "signInViaPopup",
42 SIGN_IN_VIA_REDIRECT = "signInViaRedirect",
43 UNKNOWN = "unknown",
44 VERIFY_APP = "verifyApp"
45}
46export interface AuthEventError extends Error {
47 code: string;
48 message: string;
49}
50/**
51 * @internal
52 */
53export interface AuthEvent {
54 type: AuthEventType;
55 eventId: string | null;
56 urlResponse: string | null;
57 sessionId: string | null;
58 postBody: string | null;
59 tenantId: string | null;
60 error?: AuthEventError;
61}
62/**
63 * @internal
64 */
65export interface AuthEventConsumer {
66 readonly filter: AuthEventType[];
67 eventId: string | null;
68 onAuthEvent(event: AuthEvent): unknown;
69 onError(error: FirebaseError): unknown;
70}
71/**
72 * @internal
73 */
74export interface EventManager {
75 registerConsumer(authEventConsumer: AuthEventConsumer): void;
76 unregisterConsumer(authEventConsumer: AuthEventConsumer): void;
77}
78/**
79 * We need to mark this interface as internal explicitly to exclude it in the public typings, because
80 * it references AuthInternal which has a circular dependency with UserInternal.
81 *
82 * @internal
83 */
84export interface PopupRedirectResolverInternal extends PopupRedirectResolver {
85 _shouldInitProactively: boolean;
86 _initialize(auth: AuthInternal): Promise<EventManager>;
87 _openPopup(auth: AuthInternal, provider: AuthProvider, authType: AuthEventType, eventId?: string): Promise<AuthPopup>;
88 _openRedirect(auth: AuthInternal, provider: AuthProvider, authType: AuthEventType, eventId?: string): Promise<void | never>;
89 _isIframeWebStorageSupported(auth: AuthInternal, cb: (support: boolean) => unknown): void;
90 _redirectPersistence: Persistence;
91 _originValidation(auth: Auth): Promise<void>;
92 _completeRedirectFn: (auth: Auth, resolver: PopupRedirectResolver, bypassAuthState: boolean) => Promise<UserCredential | null>;
93 _overrideRedirectResult: (auth: AuthInternal, resultGetter: () => Promise<UserCredentialInternal | null>) => void;
94}