暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

auth.d.ts 137KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044
  1. /**
  2. * Firebase Authentication
  3. *
  4. * @packageDocumentation
  5. */
  6. import { CompleteFn } from '@firebase/util';
  7. import { ErrorFactory } from '@firebase/util';
  8. import { ErrorFn } from '@firebase/util';
  9. import { FirebaseApp } from '@firebase/app';
  10. import { FirebaseError } from '@firebase/util';
  11. import { NextFn } from '@firebase/util';
  12. import { Observer } from '@firebase/util';
  13. import { Unsubscribe } from '@firebase/util';
  14. /**
  15. * A response from {@link checkActionCode}.
  16. *
  17. * @public
  18. */
  19. export declare interface ActionCodeInfo {
  20. /**
  21. * The data associated with the action code.
  22. *
  23. * @remarks
  24. * For the {@link ActionCodeOperation}.PASSWORD_RESET, {@link ActionCodeOperation}.VERIFY_EMAIL, and
  25. * {@link ActionCodeOperation}.RECOVER_EMAIL actions, this object contains an email field with the address
  26. * the email was sent to.
  27. *
  28. * For the {@link ActionCodeOperation}.RECOVER_EMAIL action, which allows a user to undo an email address
  29. * change, this object also contains a `previousEmail` field with the user account's current
  30. * email address. After the action completes, the user's email address will revert to the value
  31. * in the `email` field from the value in `previousEmail` field.
  32. *
  33. * For the {@link ActionCodeOperation}.VERIFY_AND_CHANGE_EMAIL action, which allows a user to verify the
  34. * email before updating it, this object contains a `previousEmail` field with the user account's
  35. * email address before updating. After the action completes, the user's email address will be
  36. * updated to the value in the `email` field from the value in `previousEmail` field.
  37. *
  38. * For the {@link ActionCodeOperation}.REVERT_SECOND_FACTOR_ADDITION action, which allows a user to
  39. * unenroll a newly added second factor, this object contains a `multiFactorInfo` field with
  40. * the information about the second factor. For phone second factor, the `multiFactorInfo`
  41. * is a {@link MultiFactorInfo} object, which contains the phone number.
  42. */
  43. data: {
  44. email?: string | null;
  45. multiFactorInfo?: MultiFactorInfo | null;
  46. previousEmail?: string | null;
  47. };
  48. /**
  49. * The type of operation that generated the action code.
  50. */
  51. operation: typeof ActionCodeOperation[keyof typeof ActionCodeOperation];
  52. }
  53. /**
  54. * An enumeration of the possible email action types.
  55. *
  56. * @public
  57. */
  58. export declare const ActionCodeOperation: {
  59. /** The email link sign-in action. */
  60. readonly EMAIL_SIGNIN: "EMAIL_SIGNIN";
  61. /** The password reset action. */
  62. readonly PASSWORD_RESET: "PASSWORD_RESET";
  63. /** The email revocation action. */
  64. readonly RECOVER_EMAIL: "RECOVER_EMAIL";
  65. /** The revert second factor addition email action. */
  66. readonly REVERT_SECOND_FACTOR_ADDITION: "REVERT_SECOND_FACTOR_ADDITION";
  67. /** The revert second factor addition email action. */
  68. readonly VERIFY_AND_CHANGE_EMAIL: "VERIFY_AND_CHANGE_EMAIL";
  69. /** The email verification action. */
  70. readonly VERIFY_EMAIL: "VERIFY_EMAIL";
  71. };
  72. /**
  73. * An interface that defines the required continue/state URL with optional Android and iOS
  74. * bundle identifiers.
  75. *
  76. * @public
  77. */
  78. export declare interface ActionCodeSettings {
  79. /**
  80. * Sets the Android package name.
  81. *
  82. * @remarks
  83. * This will try to open the link in an android app if it is
  84. * installed. If `installApp` is passed, it specifies whether to install the Android app if the
  85. * device supports it and the app is not already installed. If this field is provided without
  86. * a `packageName`, an error is thrown explaining that the `packageName` must be provided in
  87. * conjunction with this field. If `minimumVersion` is specified, and an older version of the
  88. * app is installed, the user is taken to the Play Store to upgrade the app.
  89. */
  90. android?: {
  91. installApp?: boolean;
  92. minimumVersion?: string;
  93. packageName: string;
  94. };
  95. /**
  96. * When set to true, the action code link will be be sent as a Universal Link or Android App
  97. * Link and will be opened by the app if installed.
  98. *
  99. * @remarks
  100. * In the false case, the code will be sent to the web widget first and then on continue will
  101. * redirect to the app if installed.
  102. *
  103. * @defaultValue false
  104. */
  105. handleCodeInApp?: boolean;
  106. /**
  107. * Sets the iOS bundle ID.
  108. *
  109. * @remarks
  110. * This will try to open the link in an iOS app if it is installed.
  111. *
  112. * App installation is not supported for iOS.
  113. */
  114. iOS?: {
  115. bundleId: string;
  116. };
  117. /**
  118. * Sets the link continue/state URL.
  119. *
  120. * @remarks
  121. * This has different meanings in different contexts:
  122. * - When the link is handled in the web action widgets, this is the deep link in the
  123. * `continueUrl` query parameter.
  124. * - When the link is handled in the app directly, this is the `continueUrl` query parameter in
  125. * the deep link of the Dynamic Link.
  126. */
  127. url: string;
  128. /**
  129. * When multiple custom dynamic link domains are defined for a project, specify which one to use
  130. * when the link is to be opened via a specified mobile app (for example, `example.page.link`).
  131. *
  132. *
  133. * @defaultValue The first domain is automatically selected.
  134. */
  135. dynamicLinkDomain?: string;
  136. }
  137. /**
  138. * @license
  139. * Copyright 2020 Google LLC
  140. *
  141. * Licensed under the Apache License, Version 2.0 (the "License");
  142. * you may not use this file except in compliance with the License.
  143. * You may obtain a copy of the License at
  144. *
  145. * http://www.apache.org/licenses/LICENSE-2.0
  146. *
  147. * Unless required by applicable law or agreed to in writing, software
  148. * distributed under the License is distributed on an "AS IS" BASIS,
  149. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  150. * See the License for the specific language governing permissions and
  151. * limitations under the License.
  152. */
  153. /**
  154. * A utility class to parse email action URLs such as password reset, email verification,
  155. * email link sign in, etc.
  156. *
  157. * @public
  158. */
  159. export declare class ActionCodeURL {
  160. /**
  161. * The API key of the email action link.
  162. */
  163. readonly apiKey: string;
  164. /**
  165. * The action code of the email action link.
  166. */
  167. readonly code: string;
  168. /**
  169. * The continue URL of the email action link. Null if not provided.
  170. */
  171. readonly continueUrl: string | null;
  172. /**
  173. * The language code of the email action link. Null if not provided.
  174. */
  175. readonly languageCode: string | null;
  176. /**
  177. * The action performed by the email action link. It returns from one of the types from
  178. * {@link ActionCodeInfo}
  179. */
  180. readonly operation: string;
  181. /**
  182. * The tenant ID of the email action link. Null if the email action is from the parent project.
  183. */
  184. readonly tenantId: string | null;
  185. /**
  186. * @param actionLink - The link from which to extract the URL.
  187. * @returns The {@link ActionCodeURL} object, or null if the link is invalid.
  188. *
  189. * @internal
  190. */
  191. constructor(actionLink: string);
  192. /**
  193. * Parses the email action link string and returns an {@link ActionCodeURL} if the link is valid,
  194. * otherwise returns null.
  195. *
  196. * @param link - The email action link string.
  197. * @returns The {@link ActionCodeURL} object, or null if the link is invalid.
  198. *
  199. * @public
  200. */
  201. static parseLink(link: string): ActionCodeURL | null;
  202. }
  203. /**
  204. * A structure containing additional user information from a federated identity provider.
  205. *
  206. * @public
  207. */
  208. export declare interface AdditionalUserInfo {
  209. /**
  210. * Whether the user is new (created via sign-up) or existing (authenticated using sign-in).
  211. */
  212. readonly isNewUser: boolean;
  213. /**
  214. * Map containing IDP-specific user data.
  215. */
  216. readonly profile: Record<string, unknown> | null;
  217. /**
  218. * Identifier for the provider used to authenticate this user.
  219. */
  220. readonly providerId: string | null;
  221. /**
  222. * The username if the provider is GitHub or Twitter.
  223. */
  224. readonly username?: string | null;
  225. }
  226. declare interface APIUserInfo {
  227. localId?: string;
  228. displayName?: string;
  229. photoUrl?: string;
  230. email?: string;
  231. emailVerified?: boolean;
  232. phoneNumber?: string;
  233. lastLoginAt?: number;
  234. createdAt?: number;
  235. tenantId?: string;
  236. passwordHash?: string;
  237. providerUserInfo?: ProviderUserInfo[];
  238. mfaInfo?: MfaEnrollment[];
  239. }
  240. /**
  241. * A verifier for domain verification and abuse prevention.
  242. *
  243. * @remarks
  244. * Currently, the only implementation is {@link RecaptchaVerifier}.
  245. *
  246. * @public
  247. */
  248. export declare interface ApplicationVerifier {
  249. /**
  250. * Identifies the type of application verifier (e.g. "recaptcha").
  251. */
  252. readonly type: string;
  253. /**
  254. * Executes the verification process.
  255. *
  256. * @returns A Promise for a token that can be used to assert the validity of a request.
  257. */
  258. verify(): Promise<string>;
  259. }
  260. declare interface ApplicationVerifierInternal extends ApplicationVerifier {
  261. /**
  262. * @internal
  263. */
  264. _reset(): void;
  265. }
  266. /**
  267. * Applies a verification code sent to the user by email or other out-of-band mechanism.
  268. *
  269. * @param auth - The {@link Auth} instance.
  270. * @param oobCode - A verification code sent to the user.
  271. *
  272. * @public
  273. */
  274. export declare function applyActionCode(auth: Auth, oobCode: string): Promise<void>;
  275. declare type AppName = string;
  276. /**
  277. * Interface representing Firebase Auth service.
  278. *
  279. * @remarks
  280. * See {@link https://firebase.google.com/docs/auth/ | Firebase Authentication} for a full guide
  281. * on how to use the Firebase Auth service.
  282. *
  283. * @public
  284. */
  285. export declare interface Auth {
  286. /** The {@link @firebase/app#FirebaseApp} associated with the `Auth` service instance. */
  287. readonly app: FirebaseApp;
  288. /** The name of the app associated with the `Auth` service instance. */
  289. readonly name: string;
  290. /** The {@link Config} used to initialize this instance. */
  291. readonly config: Config;
  292. /**
  293. * Changes the type of persistence on the `Auth` instance.
  294. *
  295. * @remarks
  296. * This will affect the currently saved Auth session and applies this type of persistence for
  297. * future sign-in requests, including sign-in with redirect requests.
  298. *
  299. * This makes it easy for a user signing in to specify whether their session should be
  300. * remembered or not. It also makes it easier to never persist the Auth state for applications
  301. * that are shared by other users or have sensitive data.
  302. *
  303. * @example
  304. * ```javascript
  305. * auth.setPersistence(browserSessionPersistence);
  306. * ```
  307. *
  308. * @param persistence - The {@link Persistence} to use.
  309. */
  310. setPersistence(persistence: Persistence): Promise<void>;
  311. /**
  312. * The {@link Auth} instance's language code.
  313. *
  314. * @remarks
  315. * This is a readable/writable property. When set to null, the default Firebase Console language
  316. * setting is applied. The language code will propagate to email action templates (password
  317. * reset, email verification and email change revocation), SMS templates for phone authentication,
  318. * reCAPTCHA verifier and OAuth popup/redirect operations provided the specified providers support
  319. * localization with the language code specified.
  320. */
  321. languageCode: string | null;
  322. /**
  323. * The {@link Auth} instance's tenant ID.
  324. *
  325. * @remarks
  326. * This is a readable/writable property. When you set the tenant ID of an {@link Auth} instance, all
  327. * future sign-in/sign-up operations will pass this tenant ID and sign in or sign up users to
  328. * the specified tenant project. When set to null, users are signed in to the parent project.
  329. *
  330. * @example
  331. * ```javascript
  332. * // Set the tenant ID on Auth instance.
  333. * auth.tenantId = 'TENANT_PROJECT_ID';
  334. *
  335. * // All future sign-in request now include tenant ID.
  336. * const result = await signInWithEmailAndPassword(auth, email, password);
  337. * // result.user.tenantId should be 'TENANT_PROJECT_ID'.
  338. * ```
  339. *
  340. * @defaultValue null
  341. */
  342. tenantId: string | null;
  343. /**
  344. * The {@link Auth} instance's settings.
  345. *
  346. * @remarks
  347. * This is used to edit/read configuration related options such as app verification mode for
  348. * phone authentication.
  349. */
  350. readonly settings: AuthSettings;
  351. /**
  352. * Adds an observer for changes to the user's sign-in state.
  353. *
  354. * @remarks
  355. * To keep the old behavior, see {@link Auth.onIdTokenChanged}.
  356. *
  357. * @param nextOrObserver - callback triggered on change.
  358. * @param error - Deprecated. This callback is never triggered. Errors
  359. * on signing in/out can be caught in promises returned from
  360. * sign-in/sign-out functions.
  361. * @param completed - Deprecated. This callback is never triggered.
  362. */
  363. onAuthStateChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
  364. /**
  365. * Adds a blocking callback that runs before an auth state change
  366. * sets a new user.
  367. *
  368. * @param callback - callback triggered before new user value is set.
  369. * If this throws, it blocks the user from being set.
  370. * @param onAbort - callback triggered if a later `beforeAuthStateChanged()`
  371. * callback throws, allowing you to undo any side effects.
  372. */
  373. beforeAuthStateChanged(callback: (user: User | null) => void | Promise<void>, onAbort?: () => void): Unsubscribe;
  374. /**
  375. * Adds an observer for changes to the signed-in user's ID token.
  376. *
  377. * @remarks
  378. * This includes sign-in, sign-out, and token refresh events.
  379. *
  380. * @param nextOrObserver - callback triggered on change.
  381. * @param error - Deprecated. This callback is never triggered. Errors
  382. * on signing in/out can be caught in promises returned from
  383. * sign-in/sign-out functions.
  384. * @param completed - Deprecated. This callback is never triggered.
  385. */
  386. onIdTokenChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
  387. /** The currently signed-in user (or null). */
  388. readonly currentUser: User | null;
  389. /** The current emulator configuration (or null). */
  390. readonly emulatorConfig: EmulatorConfig | null;
  391. /**
  392. * Asynchronously sets the provided user as {@link Auth.currentUser} on the {@link Auth} instance.
  393. *
  394. * @remarks
  395. * A new instance copy of the user provided will be made and set as currentUser.
  396. *
  397. * This will trigger {@link Auth.onAuthStateChanged} and {@link Auth.onIdTokenChanged} listeners
  398. * like other sign in methods.
  399. *
  400. * The operation fails with an error if the user to be updated belongs to a different Firebase
  401. * project.
  402. *
  403. * @param user - The new {@link User}.
  404. */
  405. updateCurrentUser(user: User | null): Promise<void>;
  406. /**
  407. * Sets the current language to the default device/browser preference.
  408. */
  409. useDeviceLanguage(): void;
  410. /**
  411. * Signs out the current user.
  412. */
  413. signOut(): Promise<void>;
  414. }
  415. /**
  416. * Interface that represents the credentials returned by an {@link AuthProvider}.
  417. *
  418. * @remarks
  419. * Implementations specify the details about each auth provider's credential requirements.
  420. *
  421. * @public
  422. */
  423. export declare class AuthCredential {
  424. /**
  425. * The authentication provider ID for the credential.
  426. *
  427. * @remarks
  428. * For example, 'facebook.com', or 'google.com'.
  429. */
  430. readonly providerId: string;
  431. /**
  432. * The authentication sign in method for the credential.
  433. *
  434. * @remarks
  435. * For example, {@link SignInMethod}.EMAIL_PASSWORD, or
  436. * {@link SignInMethod}.EMAIL_LINK. This corresponds to the sign-in method
  437. * identifier as returned in {@link fetchSignInMethodsForEmail}.
  438. */
  439. readonly signInMethod: string;
  440. /** @internal */
  441. protected constructor(
  442. /**
  443. * The authentication provider ID for the credential.
  444. *
  445. * @remarks
  446. * For example, 'facebook.com', or 'google.com'.
  447. */
  448. providerId: string,
  449. /**
  450. * The authentication sign in method for the credential.
  451. *
  452. * @remarks
  453. * For example, {@link SignInMethod}.EMAIL_PASSWORD, or
  454. * {@link SignInMethod}.EMAIL_LINK. This corresponds to the sign-in method
  455. * identifier as returned in {@link fetchSignInMethodsForEmail}.
  456. */
  457. signInMethod: string);
  458. /**
  459. * Returns a JSON-serializable representation of this object.
  460. *
  461. * @returns a JSON-serializable representation of this object.
  462. */
  463. toJSON(): object;
  464. /** @internal */
  465. _getIdTokenResponse(_auth: AuthInternal): Promise<PhoneOrOauthTokenResponse>;
  466. /** @internal */
  467. _linkToIdToken(_auth: AuthInternal, _idToken: string): Promise<IdTokenResponse>;
  468. /** @internal */
  469. _getReauthenticationResolver(_auth: AuthInternal): Promise<IdTokenResponse>;
  470. }
  471. /**
  472. * Interface for an `Auth` error.
  473. *
  474. * @public
  475. */
  476. export declare interface AuthError extends FirebaseError {
  477. /** Details about the Firebase Auth error. */
  478. readonly customData: {
  479. /** The name of the Firebase App which triggered this error. */
  480. readonly appName: string;
  481. /** The email address of the user's account, used for sign-in and linking. */
  482. readonly email?: string;
  483. /** The phone number of the user's account, used for sign-in and linking. */
  484. readonly phoneNumber?: string;
  485. /**
  486. * The tenant ID being used for sign-in and linking.
  487. *
  488. * @remarks
  489. * If you use {@link signInWithRedirect} to sign in,
  490. * you have to set the tenant ID on the {@link Auth} instance again as the tenant ID is not persisted
  491. * after redirection.
  492. */
  493. readonly tenantId?: string;
  494. };
  495. }
  496. /**
  497. * Enumeration of Firebase Auth error codes.
  498. *
  499. * @internal
  500. */
  501. declare const enum AuthErrorCode {
  502. ADMIN_ONLY_OPERATION = "admin-restricted-operation",
  503. ARGUMENT_ERROR = "argument-error",
  504. APP_NOT_AUTHORIZED = "app-not-authorized",
  505. APP_NOT_INSTALLED = "app-not-installed",
  506. CAPTCHA_CHECK_FAILED = "captcha-check-failed",
  507. CODE_EXPIRED = "code-expired",
  508. CORDOVA_NOT_READY = "cordova-not-ready",
  509. CORS_UNSUPPORTED = "cors-unsupported",
  510. CREDENTIAL_ALREADY_IN_USE = "credential-already-in-use",
  511. CREDENTIAL_MISMATCH = "custom-token-mismatch",
  512. CREDENTIAL_TOO_OLD_LOGIN_AGAIN = "requires-recent-login",
  513. DEPENDENT_SDK_INIT_BEFORE_AUTH = "dependent-sdk-initialized-before-auth",
  514. DYNAMIC_LINK_NOT_ACTIVATED = "dynamic-link-not-activated",
  515. EMAIL_CHANGE_NEEDS_VERIFICATION = "email-change-needs-verification",
  516. EMAIL_EXISTS = "email-already-in-use",
  517. EMULATOR_CONFIG_FAILED = "emulator-config-failed",
  518. EXPIRED_OOB_CODE = "expired-action-code",
  519. EXPIRED_POPUP_REQUEST = "cancelled-popup-request",
  520. INTERNAL_ERROR = "internal-error",
  521. INVALID_API_KEY = "invalid-api-key",
  522. INVALID_APP_CREDENTIAL = "invalid-app-credential",
  523. INVALID_APP_ID = "invalid-app-id",
  524. INVALID_AUTH = "invalid-user-token",
  525. INVALID_AUTH_EVENT = "invalid-auth-event",
  526. INVALID_CERT_HASH = "invalid-cert-hash",
  527. INVALID_CODE = "invalid-verification-code",
  528. INVALID_CONTINUE_URI = "invalid-continue-uri",
  529. INVALID_CORDOVA_CONFIGURATION = "invalid-cordova-configuration",
  530. INVALID_CUSTOM_TOKEN = "invalid-custom-token",
  531. INVALID_DYNAMIC_LINK_DOMAIN = "invalid-dynamic-link-domain",
  532. INVALID_EMAIL = "invalid-email",
  533. INVALID_EMULATOR_SCHEME = "invalid-emulator-scheme",
  534. INVALID_IDP_RESPONSE = "invalid-credential",
  535. INVALID_MESSAGE_PAYLOAD = "invalid-message-payload",
  536. INVALID_MFA_SESSION = "invalid-multi-factor-session",
  537. INVALID_OAUTH_CLIENT_ID = "invalid-oauth-client-id",
  538. INVALID_OAUTH_PROVIDER = "invalid-oauth-provider",
  539. INVALID_OOB_CODE = "invalid-action-code",
  540. INVALID_ORIGIN = "unauthorized-domain",
  541. INVALID_PASSWORD = "wrong-password",
  542. INVALID_PERSISTENCE = "invalid-persistence-type",
  543. INVALID_PHONE_NUMBER = "invalid-phone-number",
  544. INVALID_PROVIDER_ID = "invalid-provider-id",
  545. INVALID_RECIPIENT_EMAIL = "invalid-recipient-email",
  546. INVALID_SENDER = "invalid-sender",
  547. INVALID_SESSION_INFO = "invalid-verification-id",
  548. INVALID_TENANT_ID = "invalid-tenant-id",
  549. LOGIN_BLOCKED = "login-blocked",
  550. MFA_INFO_NOT_FOUND = "multi-factor-info-not-found",
  551. MFA_REQUIRED = "multi-factor-auth-required",
  552. MISSING_ANDROID_PACKAGE_NAME = "missing-android-pkg-name",
  553. MISSING_APP_CREDENTIAL = "missing-app-credential",
  554. MISSING_AUTH_DOMAIN = "auth-domain-config-required",
  555. MISSING_CODE = "missing-verification-code",
  556. MISSING_CONTINUE_URI = "missing-continue-uri",
  557. MISSING_IFRAME_START = "missing-iframe-start",
  558. MISSING_IOS_BUNDLE_ID = "missing-ios-bundle-id",
  559. MISSING_OR_INVALID_NONCE = "missing-or-invalid-nonce",
  560. MISSING_MFA_INFO = "missing-multi-factor-info",
  561. MISSING_MFA_SESSION = "missing-multi-factor-session",
  562. MISSING_PHONE_NUMBER = "missing-phone-number",
  563. MISSING_SESSION_INFO = "missing-verification-id",
  564. MODULE_DESTROYED = "app-deleted",
  565. NEED_CONFIRMATION = "account-exists-with-different-credential",
  566. NETWORK_REQUEST_FAILED = "network-request-failed",
  567. NULL_USER = "null-user",
  568. NO_AUTH_EVENT = "no-auth-event",
  569. NO_SUCH_PROVIDER = "no-such-provider",
  570. OPERATION_NOT_ALLOWED = "operation-not-allowed",
  571. OPERATION_NOT_SUPPORTED = "operation-not-supported-in-this-environment",
  572. POPUP_BLOCKED = "popup-blocked",
  573. POPUP_CLOSED_BY_USER = "popup-closed-by-user",
  574. PROVIDER_ALREADY_LINKED = "provider-already-linked",
  575. QUOTA_EXCEEDED = "quota-exceeded",
  576. REDIRECT_CANCELLED_BY_USER = "redirect-cancelled-by-user",
  577. REDIRECT_OPERATION_PENDING = "redirect-operation-pending",
  578. REJECTED_CREDENTIAL = "rejected-credential",
  579. SECOND_FACTOR_ALREADY_ENROLLED = "second-factor-already-in-use",
  580. SECOND_FACTOR_LIMIT_EXCEEDED = "maximum-second-factor-count-exceeded",
  581. TENANT_ID_MISMATCH = "tenant-id-mismatch",
  582. TIMEOUT = "timeout",
  583. TOKEN_EXPIRED = "user-token-expired",
  584. TOO_MANY_ATTEMPTS_TRY_LATER = "too-many-requests",
  585. UNAUTHORIZED_DOMAIN = "unauthorized-continue-uri",
  586. UNSUPPORTED_FIRST_FACTOR = "unsupported-first-factor",
  587. UNSUPPORTED_PERSISTENCE = "unsupported-persistence-type",
  588. UNSUPPORTED_TENANT_OPERATION = "unsupported-tenant-operation",
  589. UNVERIFIED_EMAIL = "unverified-email",
  590. USER_CANCELLED = "user-cancelled",
  591. USER_DELETED = "user-not-found",
  592. USER_DISABLED = "user-disabled",
  593. USER_MISMATCH = "user-mismatch",
  594. USER_SIGNED_OUT = "user-signed-out",
  595. WEAK_PASSWORD = "weak-password",
  596. WEB_STORAGE_UNSUPPORTED = "web-storage-unsupported",
  597. ALREADY_INITIALIZED = "already-initialized"
  598. }
  599. /**
  600. * A map of potential `Auth` error codes, for easier comparison with errors
  601. * thrown by the SDK.
  602. *
  603. * @remarks
  604. * Note that you can't tree-shake individual keys
  605. * in the map, so by using the map you might substantially increase your
  606. * bundle size.
  607. *
  608. * @public
  609. */
  610. export declare const AuthErrorCodes: {
  611. readonly ADMIN_ONLY_OPERATION: "auth/admin-restricted-operation";
  612. readonly ARGUMENT_ERROR: "auth/argument-error";
  613. readonly APP_NOT_AUTHORIZED: "auth/app-not-authorized";
  614. readonly APP_NOT_INSTALLED: "auth/app-not-installed";
  615. readonly CAPTCHA_CHECK_FAILED: "auth/captcha-check-failed";
  616. readonly CODE_EXPIRED: "auth/code-expired";
  617. readonly CORDOVA_NOT_READY: "auth/cordova-not-ready";
  618. readonly CORS_UNSUPPORTED: "auth/cors-unsupported";
  619. readonly CREDENTIAL_ALREADY_IN_USE: "auth/credential-already-in-use";
  620. readonly CREDENTIAL_MISMATCH: "auth/custom-token-mismatch";
  621. readonly CREDENTIAL_TOO_OLD_LOGIN_AGAIN: "auth/requires-recent-login";
  622. readonly DEPENDENT_SDK_INIT_BEFORE_AUTH: "auth/dependent-sdk-initialized-before-auth";
  623. readonly DYNAMIC_LINK_NOT_ACTIVATED: "auth/dynamic-link-not-activated";
  624. readonly EMAIL_CHANGE_NEEDS_VERIFICATION: "auth/email-change-needs-verification";
  625. readonly EMAIL_EXISTS: "auth/email-already-in-use";
  626. readonly EMULATOR_CONFIG_FAILED: "auth/emulator-config-failed";
  627. readonly EXPIRED_OOB_CODE: "auth/expired-action-code";
  628. readonly EXPIRED_POPUP_REQUEST: "auth/cancelled-popup-request";
  629. readonly INTERNAL_ERROR: "auth/internal-error";
  630. readonly INVALID_API_KEY: "auth/invalid-api-key";
  631. readonly INVALID_APP_CREDENTIAL: "auth/invalid-app-credential";
  632. readonly INVALID_APP_ID: "auth/invalid-app-id";
  633. readonly INVALID_AUTH: "auth/invalid-user-token";
  634. readonly INVALID_AUTH_EVENT: "auth/invalid-auth-event";
  635. readonly INVALID_CERT_HASH: "auth/invalid-cert-hash";
  636. readonly INVALID_CODE: "auth/invalid-verification-code";
  637. readonly INVALID_CONTINUE_URI: "auth/invalid-continue-uri";
  638. readonly INVALID_CORDOVA_CONFIGURATION: "auth/invalid-cordova-configuration";
  639. readonly INVALID_CUSTOM_TOKEN: "auth/invalid-custom-token";
  640. readonly INVALID_DYNAMIC_LINK_DOMAIN: "auth/invalid-dynamic-link-domain";
  641. readonly INVALID_EMAIL: "auth/invalid-email";
  642. readonly INVALID_EMULATOR_SCHEME: "auth/invalid-emulator-scheme";
  643. readonly INVALID_IDP_RESPONSE: "auth/invalid-credential";
  644. readonly INVALID_MESSAGE_PAYLOAD: "auth/invalid-message-payload";
  645. readonly INVALID_MFA_SESSION: "auth/invalid-multi-factor-session";
  646. readonly INVALID_OAUTH_CLIENT_ID: "auth/invalid-oauth-client-id";
  647. readonly INVALID_OAUTH_PROVIDER: "auth/invalid-oauth-provider";
  648. readonly INVALID_OOB_CODE: "auth/invalid-action-code";
  649. readonly INVALID_ORIGIN: "auth/unauthorized-domain";
  650. readonly INVALID_PASSWORD: "auth/wrong-password";
  651. readonly INVALID_PERSISTENCE: "auth/invalid-persistence-type";
  652. readonly INVALID_PHONE_NUMBER: "auth/invalid-phone-number";
  653. readonly INVALID_PROVIDER_ID: "auth/invalid-provider-id";
  654. readonly INVALID_RECIPIENT_EMAIL: "auth/invalid-recipient-email";
  655. readonly INVALID_SENDER: "auth/invalid-sender";
  656. readonly INVALID_SESSION_INFO: "auth/invalid-verification-id";
  657. readonly INVALID_TENANT_ID: "auth/invalid-tenant-id";
  658. readonly MFA_INFO_NOT_FOUND: "auth/multi-factor-info-not-found";
  659. readonly MFA_REQUIRED: "auth/multi-factor-auth-required";
  660. readonly MISSING_ANDROID_PACKAGE_NAME: "auth/missing-android-pkg-name";
  661. readonly MISSING_APP_CREDENTIAL: "auth/missing-app-credential";
  662. readonly MISSING_AUTH_DOMAIN: "auth/auth-domain-config-required";
  663. readonly MISSING_CODE: "auth/missing-verification-code";
  664. readonly MISSING_CONTINUE_URI: "auth/missing-continue-uri";
  665. readonly MISSING_IFRAME_START: "auth/missing-iframe-start";
  666. readonly MISSING_IOS_BUNDLE_ID: "auth/missing-ios-bundle-id";
  667. readonly MISSING_OR_INVALID_NONCE: "auth/missing-or-invalid-nonce";
  668. readonly MISSING_MFA_INFO: "auth/missing-multi-factor-info";
  669. readonly MISSING_MFA_SESSION: "auth/missing-multi-factor-session";
  670. readonly MISSING_PHONE_NUMBER: "auth/missing-phone-number";
  671. readonly MISSING_SESSION_INFO: "auth/missing-verification-id";
  672. readonly MODULE_DESTROYED: "auth/app-deleted";
  673. readonly NEED_CONFIRMATION: "auth/account-exists-with-different-credential";
  674. readonly NETWORK_REQUEST_FAILED: "auth/network-request-failed";
  675. readonly NULL_USER: "auth/null-user";
  676. readonly NO_AUTH_EVENT: "auth/no-auth-event";
  677. readonly NO_SUCH_PROVIDER: "auth/no-such-provider";
  678. readonly OPERATION_NOT_ALLOWED: "auth/operation-not-allowed";
  679. readonly OPERATION_NOT_SUPPORTED: "auth/operation-not-supported-in-this-environment";
  680. readonly POPUP_BLOCKED: "auth/popup-blocked";
  681. readonly POPUP_CLOSED_BY_USER: "auth/popup-closed-by-user";
  682. readonly PROVIDER_ALREADY_LINKED: "auth/provider-already-linked";
  683. readonly QUOTA_EXCEEDED: "auth/quota-exceeded";
  684. readonly REDIRECT_CANCELLED_BY_USER: "auth/redirect-cancelled-by-user";
  685. readonly REDIRECT_OPERATION_PENDING: "auth/redirect-operation-pending";
  686. readonly REJECTED_CREDENTIAL: "auth/rejected-credential";
  687. readonly SECOND_FACTOR_ALREADY_ENROLLED: "auth/second-factor-already-in-use";
  688. readonly SECOND_FACTOR_LIMIT_EXCEEDED: "auth/maximum-second-factor-count-exceeded";
  689. readonly TENANT_ID_MISMATCH: "auth/tenant-id-mismatch";
  690. readonly TIMEOUT: "auth/timeout";
  691. readonly TOKEN_EXPIRED: "auth/user-token-expired";
  692. readonly TOO_MANY_ATTEMPTS_TRY_LATER: "auth/too-many-requests";
  693. readonly UNAUTHORIZED_DOMAIN: "auth/unauthorized-continue-uri";
  694. readonly UNSUPPORTED_FIRST_FACTOR: "auth/unsupported-first-factor";
  695. readonly UNSUPPORTED_PERSISTENCE: "auth/unsupported-persistence-type";
  696. readonly UNSUPPORTED_TENANT_OPERATION: "auth/unsupported-tenant-operation";
  697. readonly UNVERIFIED_EMAIL: "auth/unverified-email";
  698. readonly USER_CANCELLED: "auth/user-cancelled";
  699. readonly USER_DELETED: "auth/user-not-found";
  700. readonly USER_DISABLED: "auth/user-disabled";
  701. readonly USER_MISMATCH: "auth/user-mismatch";
  702. readonly USER_SIGNED_OUT: "auth/user-signed-out";
  703. readonly WEAK_PASSWORD: "auth/weak-password";
  704. readonly WEB_STORAGE_UNSUPPORTED: "auth/web-storage-unsupported";
  705. readonly ALREADY_INITIALIZED: "auth/already-initialized";
  706. };
  707. /**
  708. * A mapping of error codes to error messages.
  709. *
  710. * @remarks
  711. *
  712. * While error messages are useful for debugging (providing verbose textual
  713. * context around what went wrong), these strings take up a lot of space in the
  714. * compiled code. When deploying code in production, using {@link prodErrorMap}
  715. * will save you roughly 10k compressed/gzipped over {@link debugErrorMap}. You
  716. * can select the error map during initialization:
  717. *
  718. * ```javascript
  719. * initializeAuth(app, {errorMap: debugErrorMap})
  720. * ```
  721. *
  722. * When initializing Auth, {@link prodErrorMap} is default.
  723. *
  724. * @public
  725. */
  726. export declare interface AuthErrorMap {
  727. }
  728. /**
  729. * @internal
  730. */
  731. declare interface AuthErrorParams extends GenericAuthErrorParams {
  732. [AuthErrorCode.ARGUMENT_ERROR]: {
  733. appName?: AppName;
  734. };
  735. [AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH]: {
  736. appName?: AppName;
  737. };
  738. [AuthErrorCode.INTERNAL_ERROR]: {
  739. appName?: AppName;
  740. };
  741. [AuthErrorCode.LOGIN_BLOCKED]: {
  742. appName?: AppName;
  743. originalMessage?: string;
  744. };
  745. [AuthErrorCode.OPERATION_NOT_SUPPORTED]: {
  746. appName?: AppName;
  747. };
  748. [AuthErrorCode.NO_AUTH_EVENT]: {
  749. appName?: AppName;
  750. };
  751. [AuthErrorCode.MFA_REQUIRED]: {
  752. appName: AppName;
  753. _serverResponse: IdTokenMfaResponse;
  754. };
  755. [AuthErrorCode.INVALID_CORDOVA_CONFIGURATION]: {
  756. appName: AppName;
  757. missingPlugin?: string;
  758. };
  759. }
  760. /**
  761. * @internal
  762. */
  763. declare interface AuthEvent {
  764. type: AuthEventType;
  765. eventId: string | null;
  766. urlResponse: string | null;
  767. sessionId: string | null;
  768. postBody: string | null;
  769. tenantId: string | null;
  770. error?: AuthEventError;
  771. }
  772. /**
  773. * @internal
  774. */
  775. declare interface AuthEventConsumer {
  776. readonly filter: AuthEventType[];
  777. eventId: string | null;
  778. onAuthEvent(event: AuthEvent): unknown;
  779. onError(error: FirebaseError): unknown;
  780. }
  781. declare interface AuthEventError extends Error {
  782. code: string;
  783. message: string;
  784. }
  785. /**
  786. * @internal
  787. */
  788. declare const enum AuthEventType {
  789. LINK_VIA_POPUP = "linkViaPopup",
  790. LINK_VIA_REDIRECT = "linkViaRedirect",
  791. REAUTH_VIA_POPUP = "reauthViaPopup",
  792. REAUTH_VIA_REDIRECT = "reauthViaRedirect",
  793. SIGN_IN_VIA_POPUP = "signInViaPopup",
  794. SIGN_IN_VIA_REDIRECT = "signInViaRedirect",
  795. UNKNOWN = "unknown",
  796. VERIFY_APP = "verifyApp"
  797. }
  798. /**
  799. * UserInternal and AuthInternal reference each other, so both of them are included in the public typings.
  800. * In order to exclude them, we mark them as internal explicitly.
  801. *
  802. * @internal
  803. */
  804. declare interface AuthInternal extends Auth {
  805. currentUser: User | null;
  806. emulatorConfig: EmulatorConfig | null;
  807. _canInitEmulator: boolean;
  808. _isInitialized: boolean;
  809. _initializationPromise: Promise<void> | null;
  810. _updateCurrentUser(user: UserInternal | null): Promise<void>;
  811. _onStorageEvent(): void;
  812. _notifyListenersIfCurrent(user: UserInternal): void;
  813. _persistUserIfCurrent(user: UserInternal): Promise<void>;
  814. _setRedirectUser(user: UserInternal | null, popupRedirectResolver?: PopupRedirectResolver): Promise<void>;
  815. _redirectUserForId(id: string): Promise<UserInternal | null>;
  816. _popupRedirectResolver: PopupRedirectResolverInternal | null;
  817. _key(): string;
  818. _startProactiveRefresh(): void;
  819. _stopProactiveRefresh(): void;
  820. _getPersistence(): string;
  821. _logFramework(framework: string): void;
  822. _getFrameworks(): readonly string[];
  823. _getAdditionalHeaders(): Promise<Record<string, string>>;
  824. readonly name: AppName;
  825. readonly config: ConfigInternal;
  826. languageCode: string | null;
  827. tenantId: string | null;
  828. readonly settings: AuthSettings;
  829. _errorFactory: ErrorFactory<AuthErrorCode, AuthErrorParams>;
  830. useDeviceLanguage(): void;
  831. signOut(): Promise<void>;
  832. }
  833. declare class AuthPopup {
  834. readonly window: Window | null;
  835. associatedEvent: string | null;
  836. constructor(window: Window | null);
  837. close(): void;
  838. }
  839. /**
  840. * Interface that represents an auth provider, used to facilitate creating {@link AuthCredential}.
  841. *
  842. * @public
  843. */
  844. export declare interface AuthProvider {
  845. /**
  846. * Provider for which credentials can be constructed.
  847. */
  848. readonly providerId: string;
  849. }
  850. /**
  851. * Interface representing an {@link Auth} instance's settings.
  852. *
  853. * @remarks Currently used for enabling/disabling app verification for phone Auth testing.
  854. *
  855. * @public
  856. */
  857. export declare interface AuthSettings {
  858. /**
  859. * When set, this property disables app verification for the purpose of testing phone
  860. * authentication. For this property to take effect, it needs to be set before rendering a
  861. * reCAPTCHA app verifier. When this is disabled, a mock reCAPTCHA is rendered instead. This is
  862. * useful for manual testing during development or for automated integration tests.
  863. *
  864. * In order to use this feature, you will need to
  865. * {@link https://firebase.google.com/docs/auth/web/phone-auth#test-with-whitelisted-phone-numbers | whitelist your phone number}
  866. * via the Firebase Console.
  867. *
  868. * The default value is false (app verification is enabled).
  869. */
  870. appVerificationDisabledForTesting: boolean;
  871. }
  872. /**
  873. * MFA Info as returned by the API
  874. */
  875. declare interface BaseMfaEnrollment {
  876. mfaEnrollmentId: string;
  877. enrolledAt: number;
  878. displayName?: string;
  879. }
  880. /**
  881. * Common code to all OAuth providers. This is separate from the
  882. * {@link OAuthProvider} so that child providers (like
  883. * {@link GoogleAuthProvider}) don't inherit the `credential` instance method.
  884. * Instead, they rely on a static `credential` method.
  885. */
  886. declare abstract class BaseOAuthProvider extends FederatedAuthProvider implements AuthProvider {
  887. /** @internal */
  888. private scopes;
  889. /**
  890. * Add an OAuth scope to the credential.
  891. *
  892. * @param scope - Provider OAuth scope to add.
  893. */
  894. addScope(scope: string): AuthProvider;
  895. /**
  896. * Retrieve the current list of OAuth scopes.
  897. */
  898. getScopes(): string[];
  899. }
  900. /**
  901. * Adds a blocking callback that runs before an auth state change
  902. * sets a new user.
  903. *
  904. * @param auth - The {@link Auth} instance.
  905. * @param callback - callback triggered before new user value is set.
  906. * If this throws, it blocks the user from being set.
  907. * @param onAbort - callback triggered if a later `beforeAuthStateChanged()`
  908. * callback throws, allowing you to undo any side effects.
  909. */
  910. export declare function beforeAuthStateChanged(auth: Auth, callback: (user: User | null) => void | Promise<void>, onAbort?: () => void): Unsubscribe;
  911. /**
  912. * An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
  913. * for the underlying storage.
  914. *
  915. * @public
  916. */
  917. export declare const browserLocalPersistence: Persistence;
  918. /**
  919. * An implementation of {@link PopupRedirectResolver} suitable for browser
  920. * based applications.
  921. *
  922. * @public
  923. */
  924. export declare const browserPopupRedirectResolver: PopupRedirectResolver;
  925. /**
  926. * An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
  927. * for the underlying storage.
  928. *
  929. * @public
  930. */
  931. export declare const browserSessionPersistence: Persistence;
  932. /**
  933. * Checks a verification code sent to the user by email or other out-of-band mechanism.
  934. *
  935. * @returns metadata about the code.
  936. *
  937. * @param auth - The {@link Auth} instance.
  938. * @param oobCode - A verification code sent to the user.
  939. *
  940. * @public
  941. */
  942. export declare function checkActionCode(auth: Auth, oobCode: string): Promise<ActionCodeInfo>;
  943. /**
  944. * @internal
  945. */
  946. declare const enum ClientPlatform {
  947. BROWSER = "Browser",
  948. NODE = "Node",
  949. REACT_NATIVE = "ReactNative",
  950. CORDOVA = "Cordova",
  951. WORKER = "Worker"
  952. }
  953. export { CompleteFn }
  954. /**
  955. * Interface representing the `Auth` config.
  956. *
  957. * @public
  958. */
  959. export declare interface Config {
  960. /**
  961. * The API Key used to communicate with the Firebase Auth backend.
  962. */
  963. apiKey: string;
  964. /**
  965. * The host at which the Firebase Auth backend is running.
  966. */
  967. apiHost: string;
  968. /**
  969. * The scheme used to communicate with the Firebase Auth backend.
  970. */
  971. apiScheme: string;
  972. /**
  973. * The host at which the Secure Token API is running.
  974. */
  975. tokenApiHost: string;
  976. /**
  977. * The SDK Client Version.
  978. */
  979. sdkClientVersion: string;
  980. /**
  981. * The domain at which the web widgets are hosted (provided via Firebase Config).
  982. */
  983. authDomain?: string;
  984. }
  985. /**
  986. * @internal
  987. */
  988. declare interface ConfigInternal extends Config {
  989. /**
  990. * @readonly
  991. */
  992. emulator?: {
  993. url: string;
  994. };
  995. /**
  996. * @readonly
  997. */
  998. clientPlatform: ClientPlatform;
  999. }
  1000. /**
  1001. * A result from a phone number sign-in, link, or reauthenticate call.
  1002. *
  1003. * @public
  1004. */
  1005. export declare interface ConfirmationResult {
  1006. /**
  1007. * The phone number authentication operation's verification ID.
  1008. *
  1009. * @remarks
  1010. * This can be used along with the verification code to initialize a
  1011. * {@link PhoneAuthCredential}.
  1012. */
  1013. readonly verificationId: string;
  1014. /**
  1015. * Finishes a phone number sign-in, link, or reauthentication.
  1016. *
  1017. * @example
  1018. * ```javascript
  1019. * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
  1020. * // Obtain verificationCode from the user.
  1021. * const userCredential = await confirmationResult.confirm(verificationCode);
  1022. * ```
  1023. *
  1024. * @param verificationCode - The code that was sent to the user's mobile device.
  1025. */
  1026. confirm(verificationCode: string): Promise<UserCredential>;
  1027. }
  1028. /**
  1029. * Completes the password reset process, given a confirmation code and new password.
  1030. *
  1031. * @param auth - The {@link Auth} instance.
  1032. * @param oobCode - A confirmation code sent to the user.
  1033. * @param newPassword - The new password.
  1034. *
  1035. * @public
  1036. */
  1037. export declare function confirmPasswordReset(auth: Auth, oobCode: string, newPassword: string): Promise<void>;
  1038. /**
  1039. * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
  1040. * Firebase Auth services.
  1041. *
  1042. * @remarks
  1043. * This must be called synchronously immediately following the first call to
  1044. * {@link initializeAuth}. Do not use with production credentials as emulator
  1045. * traffic is not encrypted.
  1046. *
  1047. *
  1048. * @example
  1049. * ```javascript
  1050. * connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
  1051. * ```
  1052. *
  1053. * @param auth - The {@link Auth} instance.
  1054. * @param url - The URL at which the emulator is running (eg, 'http://localhost:9099').
  1055. * @param options - Optional. `options.disableWarnings` defaults to `false`. Set it to
  1056. * `true` to disable the warning banner attached to the DOM.
  1057. *
  1058. * @public
  1059. */
  1060. export declare function connectAuthEmulator(auth: Auth, url: string, options?: {
  1061. disableWarnings: boolean;
  1062. }): void;
  1063. /**
  1064. * Creates a new user account associated with the specified email address and password.
  1065. *
  1066. * @remarks
  1067. * On successful creation of the user account, this user will also be signed in to your application.
  1068. *
  1069. * User account creation can fail if the account already exists or the password is invalid.
  1070. *
  1071. * Note: The email address acts as a unique identifier for the user and enables an email-based
  1072. * password reset. This function will create a new user account and set the initial user password.
  1073. *
  1074. * @param auth - The {@link Auth} instance.
  1075. * @param email - The user's email address.
  1076. * @param password - The user's chosen password.
  1077. *
  1078. * @public
  1079. */
  1080. export declare function createUserWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>;
  1081. /**
  1082. * Map of OAuth Custom Parameters.
  1083. *
  1084. * @public
  1085. */
  1086. export declare type CustomParameters = Record<string, string>;
  1087. /**
  1088. * A verbose error map with detailed descriptions for most error codes.
  1089. *
  1090. * See discussion at {@link AuthErrorMap}
  1091. *
  1092. * @public
  1093. */
  1094. export declare const debugErrorMap: AuthErrorMap;
  1095. /**
  1096. * Deletes and signs out the user.
  1097. *
  1098. * @remarks
  1099. * Important: this is a security-sensitive operation that requires the user to have recently
  1100. * signed in. If this requirement isn't met, ask the user to authenticate again and then call
  1101. * {@link reauthenticateWithCredential}.
  1102. *
  1103. * @param user - The user.
  1104. *
  1105. * @public
  1106. */
  1107. export declare function deleteUser(user: User): Promise<void>;
  1108. /**
  1109. * The dependencies that can be used to initialize an {@link Auth} instance.
  1110. *
  1111. * @remarks
  1112. *
  1113. * The modular SDK enables tree shaking by allowing explicit declarations of
  1114. * dependencies. For example, a web app does not need to include code that
  1115. * enables Cordova redirect sign in. That functionality is therefore split into
  1116. * {@link browserPopupRedirectResolver} and
  1117. * {@link cordovaPopupRedirectResolver}. The dependencies object is how Auth is
  1118. * configured to reduce bundle sizes.
  1119. *
  1120. * There are two ways to initialize an {@link Auth} instance: {@link getAuth} and
  1121. * {@link initializeAuth}. `getAuth` initializes everything using
  1122. * platform-specific configurations, while `initializeAuth` takes a
  1123. * `Dependencies` object directly, giving you more control over what is used.
  1124. *
  1125. * @public
  1126. */
  1127. export declare interface Dependencies {
  1128. /**
  1129. * Which {@link Persistence} to use. If this is an array, the first
  1130. * `Persistence` that the device supports is used. The SDK searches for an
  1131. * existing account in order and, if one is found in a secondary
  1132. * `Persistence`, the account is moved to the primary `Persistence`.
  1133. *
  1134. * If no persistence is provided, the SDK falls back on
  1135. * {@link inMemoryPersistence}.
  1136. */
  1137. persistence?: Persistence | Persistence[];
  1138. /**
  1139. * The {@link PopupRedirectResolver} to use. This value depends on the
  1140. * platform. Options are {@link browserPopupRedirectResolver} and
  1141. * {@link cordovaPopupRedirectResolver}. This field is optional if neither
  1142. * {@link signInWithPopup} or {@link signInWithRedirect} are being used.
  1143. */
  1144. popupRedirectResolver?: PopupRedirectResolver;
  1145. /**
  1146. * Which {@link AuthErrorMap} to use.
  1147. */
  1148. errorMap?: AuthErrorMap;
  1149. }
  1150. /**
  1151. * Interface that represents the credentials returned by {@link EmailAuthProvider} for
  1152. * {@link ProviderId}.PASSWORD
  1153. *
  1154. * @remarks
  1155. * Covers both {@link SignInMethod}.EMAIL_PASSWORD and
  1156. * {@link SignInMethod}.EMAIL_LINK.
  1157. *
  1158. * @public
  1159. */
  1160. export declare class EmailAuthCredential extends AuthCredential {
  1161. /** @internal */
  1162. readonly _email: string;
  1163. /** @internal */
  1164. readonly _password: string;
  1165. /** @internal */
  1166. readonly _tenantId: string | null;
  1167. /** @internal */
  1168. private constructor();
  1169. /** @internal */
  1170. static _fromEmailAndPassword(email: string, password: string): EmailAuthCredential;
  1171. /** @internal */
  1172. static _fromEmailAndCode(email: string, oobCode: string, tenantId?: string | null): EmailAuthCredential;
  1173. /** {@inheritdoc AuthCredential.toJSON} */
  1174. toJSON(): object;
  1175. /**
  1176. * Static method to deserialize a JSON representation of an object into an {@link AuthCredential}.
  1177. *
  1178. * @param json - Either `object` or the stringified representation of the object. When string is
  1179. * provided, `JSON.parse` would be called first.
  1180. *
  1181. * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
  1182. */
  1183. static fromJSON(json: object | string): EmailAuthCredential | null;
  1184. /** @internal */
  1185. _getIdTokenResponse(auth: AuthInternal): Promise<IdTokenResponse>;
  1186. /** @internal */
  1187. _linkToIdToken(auth: AuthInternal, idToken: string): Promise<IdTokenResponse>;
  1188. /** @internal */
  1189. _getReauthenticationResolver(auth: AuthInternal): Promise<IdTokenResponse>;
  1190. }
  1191. /**
  1192. * Provider for generating {@link EmailAuthCredential}.
  1193. *
  1194. * @public
  1195. */
  1196. export declare class EmailAuthProvider implements AuthProvider {
  1197. /**
  1198. * Always set to {@link ProviderId}.PASSWORD, even for email link.
  1199. */
  1200. static readonly PROVIDER_ID: 'password';
  1201. /**
  1202. * Always set to {@link SignInMethod}.EMAIL_PASSWORD.
  1203. */
  1204. static readonly EMAIL_PASSWORD_SIGN_IN_METHOD: 'password';
  1205. /**
  1206. * Always set to {@link SignInMethod}.EMAIL_LINK.
  1207. */
  1208. static readonly EMAIL_LINK_SIGN_IN_METHOD: 'emailLink';
  1209. /**
  1210. * Always set to {@link ProviderId}.PASSWORD, even for email link.
  1211. */
  1212. readonly providerId: "password";
  1213. /**
  1214. * Initialize an {@link AuthCredential} using an email and password.
  1215. *
  1216. * @example
  1217. * ```javascript
  1218. * const authCredential = EmailAuthProvider.credential(email, password);
  1219. * const userCredential = await signInWithCredential(auth, authCredential);
  1220. * ```
  1221. *
  1222. * @example
  1223. * ```javascript
  1224. * const userCredential = await signInWithEmailAndPassword(auth, email, password);
  1225. * ```
  1226. *
  1227. * @param email - Email address.
  1228. * @param password - User account password.
  1229. * @returns The auth provider credential.
  1230. */
  1231. static credential(email: string, password: string): EmailAuthCredential;
  1232. /**
  1233. * Initialize an {@link AuthCredential} using an email and an email link after a sign in with
  1234. * email link operation.
  1235. *
  1236. * @example
  1237. * ```javascript
  1238. * const authCredential = EmailAuthProvider.credentialWithLink(auth, email, emailLink);
  1239. * const userCredential = await signInWithCredential(auth, authCredential);
  1240. * ```
  1241. *
  1242. * @example
  1243. * ```javascript
  1244. * await sendSignInLinkToEmail(auth, email);
  1245. * // Obtain emailLink from user.
  1246. * const userCredential = await signInWithEmailLink(auth, email, emailLink);
  1247. * ```
  1248. *
  1249. * @param auth - The {@link Auth} instance used to verify the link.
  1250. * @param email - Email address.
  1251. * @param emailLink - Sign-in email link.
  1252. * @returns - The auth provider credential.
  1253. */
  1254. static credentialWithLink(email: string, emailLink: string): EmailAuthCredential;
  1255. }
  1256. /**
  1257. * Configuration of Firebase Authentication Emulator.
  1258. * @public
  1259. */
  1260. export declare interface EmulatorConfig {
  1261. /**
  1262. * The protocol used to communicate with the emulator ("http"/"https").
  1263. */
  1264. readonly protocol: string;
  1265. /**
  1266. * The hostname of the emulator, which may be a domain ("localhost"), IPv4 address ("127.0.0.1")
  1267. * or quoted IPv6 address ("[::1]").
  1268. */
  1269. readonly host: string;
  1270. /**
  1271. * The port of the emulator, or null if port isn't specified (i.e. protocol default).
  1272. */
  1273. readonly port: number | null;
  1274. /**
  1275. * The emulator-specific options.
  1276. */
  1277. readonly options: {
  1278. /**
  1279. * Whether the warning banner attached to the DOM was disabled.
  1280. */
  1281. readonly disableWarnings: boolean;
  1282. };
  1283. }
  1284. export { ErrorFn }
  1285. /**
  1286. * @internal
  1287. */
  1288. declare interface EventManager {
  1289. registerConsumer(authEventConsumer: AuthEventConsumer): void;
  1290. unregisterConsumer(authEventConsumer: AuthEventConsumer): void;
  1291. }
  1292. /**
  1293. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.FACEBOOK.
  1294. *
  1295. * @example
  1296. * ```javascript
  1297. * // Sign in using a redirect.
  1298. * const provider = new FacebookAuthProvider();
  1299. * // Start a sign in process for an unauthenticated user.
  1300. * provider.addScope('user_birthday');
  1301. * await signInWithRedirect(auth, provider);
  1302. * // This will trigger a full page redirect away from your app
  1303. *
  1304. * // After returning from the redirect when your app initializes you can obtain the result
  1305. * const result = await getRedirectResult(auth);
  1306. * if (result) {
  1307. * // This is the signed-in user
  1308. * const user = result.user;
  1309. * // This gives you a Facebook Access Token.
  1310. * const credential = FacebookAuthProvider.credentialFromResult(result);
  1311. * const token = credential.accessToken;
  1312. * }
  1313. * ```
  1314. *
  1315. * @example
  1316. * ```javascript
  1317. * // Sign in using a popup.
  1318. * const provider = new FacebookAuthProvider();
  1319. * provider.addScope('user_birthday');
  1320. * const result = await signInWithPopup(auth, provider);
  1321. *
  1322. * // The signed-in user info.
  1323. * const user = result.user;
  1324. * // This gives you a Facebook Access Token.
  1325. * const credential = FacebookAuthProvider.credentialFromResult(result);
  1326. * const token = credential.accessToken;
  1327. * ```
  1328. *
  1329. * @public
  1330. */
  1331. export declare class FacebookAuthProvider extends BaseOAuthProvider {
  1332. /** Always set to {@link SignInMethod}.FACEBOOK. */
  1333. static readonly FACEBOOK_SIGN_IN_METHOD: 'facebook.com';
  1334. /** Always set to {@link ProviderId}.FACEBOOK. */
  1335. static readonly PROVIDER_ID: 'facebook.com';
  1336. constructor();
  1337. /**
  1338. * Creates a credential for Facebook.
  1339. *
  1340. * @example
  1341. * ```javascript
  1342. * // `event` from the Facebook auth.authResponseChange callback.
  1343. * const credential = FacebookAuthProvider.credential(event.authResponse.accessToken);
  1344. * const result = await signInWithCredential(credential);
  1345. * ```
  1346. *
  1347. * @param accessToken - Facebook access token.
  1348. */
  1349. static credential(accessToken: string): OAuthCredential;
  1350. /**
  1351. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  1352. *
  1353. * @param userCredential - The user credential.
  1354. */
  1355. static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
  1356. /**
  1357. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  1358. * thrown during a sign-in, link, or reauthenticate operation.
  1359. *
  1360. * @param userCredential - The user credential.
  1361. */
  1362. static credentialFromError(error: FirebaseError): OAuthCredential | null;
  1363. private static credentialFromTaggedObject;
  1364. }
  1365. /**
  1366. * An enum of factors that may be used for multifactor authentication.
  1367. *
  1368. * @public
  1369. */
  1370. export declare const FactorId: {
  1371. /** Phone as second factor */
  1372. readonly PHONE: "phone";
  1373. };
  1374. /**
  1375. * The base class for all Federated providers (OAuth (including OIDC), SAML).
  1376. *
  1377. * This class is not meant to be instantiated directly.
  1378. *
  1379. * @public
  1380. */
  1381. declare abstract class FederatedAuthProvider implements AuthProvider {
  1382. readonly providerId: string;
  1383. /** @internal */
  1384. defaultLanguageCode: string | null;
  1385. /** @internal */
  1386. private customParameters;
  1387. /**
  1388. * Constructor for generic OAuth providers.
  1389. *
  1390. * @param providerId - Provider for which credentials should be generated.
  1391. */
  1392. constructor(providerId: string);
  1393. /**
  1394. * Set the language gode.
  1395. *
  1396. * @param languageCode - language code
  1397. */
  1398. setDefaultLanguage(languageCode: string | null): void;
  1399. /**
  1400. * Sets the OAuth custom parameters to pass in an OAuth request for popup and redirect sign-in
  1401. * operations.
  1402. *
  1403. * @remarks
  1404. * For a detailed list, check the reserved required OAuth 2.0 parameters such as `client_id`,
  1405. * `redirect_uri`, `scope`, `response_type`, and `state` are not allowed and will be ignored.
  1406. *
  1407. * @param customOAuthParameters - The custom OAuth parameters to pass in the OAuth request.
  1408. */
  1409. setCustomParameters(customOAuthParameters: CustomParameters): AuthProvider;
  1410. /**
  1411. * Retrieve the current list of {@link CustomParameters}.
  1412. */
  1413. getCustomParameters(): CustomParameters;
  1414. }
  1415. /**
  1416. * Gets the list of possible sign in methods for the given email address.
  1417. *
  1418. * @remarks
  1419. * This is useful to differentiate methods of sign-in for the same provider, eg.
  1420. * {@link EmailAuthProvider} which has 2 methods of sign-in,
  1421. * {@link SignInMethod}.EMAIL_PASSWORD and
  1422. * {@link SignInMethod}.EMAIL_LINK.
  1423. *
  1424. * @param auth - The {@link Auth} instance.
  1425. * @param email - The user's email address.
  1426. *
  1427. * @public
  1428. */
  1429. export declare function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<string[]>;
  1430. declare interface FinalizeMfaResponse {
  1431. idToken: string;
  1432. refreshToken: string;
  1433. }
  1434. /**
  1435. * @internal
  1436. */
  1437. declare type GenericAuthErrorParams = {
  1438. [key in Exclude<AuthErrorCode, AuthErrorCode.ARGUMENT_ERROR | AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH | AuthErrorCode.INTERNAL_ERROR | AuthErrorCode.MFA_REQUIRED | AuthErrorCode.NO_AUTH_EVENT | AuthErrorCode.OPERATION_NOT_SUPPORTED>]: {
  1439. appName?: AppName;
  1440. email?: string;
  1441. phoneNumber?: string;
  1442. message?: string;
  1443. };
  1444. };
  1445. /**
  1446. * Extracts provider specific {@link AdditionalUserInfo} for the given credential.
  1447. *
  1448. * @param userCredential - The user credential.
  1449. *
  1450. * @public
  1451. */
  1452. export declare function getAdditionalUserInfo(userCredential: UserCredential): AdditionalUserInfo | null;
  1453. /**
  1454. * Returns the Auth instance associated with the provided {@link @firebase/app#FirebaseApp}.
  1455. * If no instance exists, initializes an Auth instance with platform-specific default dependencies.
  1456. *
  1457. * @param app - The Firebase App.
  1458. *
  1459. * @public
  1460. */
  1461. export declare function getAuth(app?: FirebaseApp): Auth;
  1462. /**
  1463. * Returns a JSON Web Token (JWT) used to identify the user to a Firebase service.
  1464. *
  1465. * @remarks
  1466. * Returns the current token if it has not expired or if it will not expire in the next five
  1467. * minutes. Otherwise, this will refresh the token and return a new one.
  1468. *
  1469. * @param user - The user.
  1470. * @param forceRefresh - Force refresh regardless of token expiration.
  1471. *
  1472. * @public
  1473. */
  1474. export declare function getIdToken(user: User, forceRefresh?: boolean): Promise<string>;
  1475. /**
  1476. * Returns a deserialized JSON Web Token (JWT) used to identitfy the user to a Firebase service.
  1477. *
  1478. * @remarks
  1479. * Returns the current token if it has not expired or if it will not expire in the next five
  1480. * minutes. Otherwise, this will refresh the token and return a new one.
  1481. *
  1482. * @param user - The user.
  1483. * @param forceRefresh - Force refresh regardless of token expiration.
  1484. *
  1485. * @public
  1486. */
  1487. export declare function getIdTokenResult(user: User, forceRefresh?: boolean): Promise<IdTokenResult>;
  1488. /**
  1489. * Provides a {@link MultiFactorResolver} suitable for completion of a
  1490. * multi-factor flow.
  1491. *
  1492. * @param auth - The {@link Auth} instance.
  1493. * @param error - The {@link MultiFactorError} raised during a sign-in, or
  1494. * reauthentication operation.
  1495. *
  1496. * @public
  1497. */
  1498. export declare function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver;
  1499. /**
  1500. * Returns a {@link UserCredential} from the redirect-based sign-in flow.
  1501. *
  1502. * @remarks
  1503. * If sign-in succeeded, returns the signed in user. If sign-in was unsuccessful, fails with an
  1504. * error. If no redirect operation was called, returns `null`.
  1505. *
  1506. * @example
  1507. * ```javascript
  1508. * // Sign in using a redirect.
  1509. * const provider = new FacebookAuthProvider();
  1510. * // You can add additional scopes to the provider:
  1511. * provider.addScope('user_birthday');
  1512. * // Start a sign in process for an unauthenticated user.
  1513. * await signInWithRedirect(auth, provider);
  1514. * // This will trigger a full page redirect away from your app
  1515. *
  1516. * // After returning from the redirect when your app initializes you can obtain the result
  1517. * const result = await getRedirectResult(auth);
  1518. * if (result) {
  1519. * // This is the signed-in user
  1520. * const user = result.user;
  1521. * // This gives you a Facebook Access Token.
  1522. * const credential = provider.credentialFromResult(auth, result);
  1523. * const token = credential.accessToken;
  1524. * }
  1525. * // As this API can be used for sign-in, linking and reauthentication,
  1526. * // check the operationType to determine what triggered this redirect
  1527. * // operation.
  1528. * const operationType = result.operationType;
  1529. * ```
  1530. *
  1531. * @param auth - The {@link Auth} instance.
  1532. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  1533. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  1534. *
  1535. * @public
  1536. */
  1537. export declare function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): Promise<UserCredential | null>;
  1538. /**
  1539. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.GITHUB.
  1540. *
  1541. * @remarks
  1542. * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect directly, or use
  1543. * the {@link signInWithPopup} handler:
  1544. *
  1545. * @example
  1546. * ```javascript
  1547. * // Sign in using a redirect.
  1548. * const provider = new GithubAuthProvider();
  1549. * // Start a sign in process for an unauthenticated user.
  1550. * provider.addScope('repo');
  1551. * await signInWithRedirect(auth, provider);
  1552. * // This will trigger a full page redirect away from your app
  1553. *
  1554. * // After returning from the redirect when your app initializes you can obtain the result
  1555. * const result = await getRedirectResult(auth);
  1556. * if (result) {
  1557. * // This is the signed-in user
  1558. * const user = result.user;
  1559. * // This gives you a Github Access Token.
  1560. * const credential = GithubAuthProvider.credentialFromResult(result);
  1561. * const token = credential.accessToken;
  1562. * }
  1563. * ```
  1564. *
  1565. * @example
  1566. * ```javascript
  1567. * // Sign in using a popup.
  1568. * const provider = new GithubAuthProvider();
  1569. * provider.addScope('repo');
  1570. * const result = await signInWithPopup(auth, provider);
  1571. *
  1572. * // The signed-in user info.
  1573. * const user = result.user;
  1574. * // This gives you a Github Access Token.
  1575. * const credential = GithubAuthProvider.credentialFromResult(result);
  1576. * const token = credential.accessToken;
  1577. * ```
  1578. * @public
  1579. */
  1580. export declare class GithubAuthProvider extends BaseOAuthProvider {
  1581. /** Always set to {@link SignInMethod}.GITHUB. */
  1582. static readonly GITHUB_SIGN_IN_METHOD: 'github.com';
  1583. /** Always set to {@link ProviderId}.GITHUB. */
  1584. static readonly PROVIDER_ID: 'github.com';
  1585. constructor();
  1586. /**
  1587. * Creates a credential for Github.
  1588. *
  1589. * @param accessToken - Github access token.
  1590. */
  1591. static credential(accessToken: string): OAuthCredential;
  1592. /**
  1593. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  1594. *
  1595. * @param userCredential - The user credential.
  1596. */
  1597. static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
  1598. /**
  1599. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  1600. * thrown during a sign-in, link, or reauthenticate operation.
  1601. *
  1602. * @param userCredential - The user credential.
  1603. */
  1604. static credentialFromError(error: FirebaseError): OAuthCredential | null;
  1605. private static credentialFromTaggedObject;
  1606. }
  1607. /**
  1608. * Provider for generating an an {@link OAuthCredential} for {@link ProviderId}.GOOGLE.
  1609. *
  1610. * @example
  1611. * ```javascript
  1612. * // Sign in using a redirect.
  1613. * const provider = new GoogleAuthProvider();
  1614. * // Start a sign in process for an unauthenticated user.
  1615. * provider.addScope('profile');
  1616. * provider.addScope('email');
  1617. * await signInWithRedirect(auth, provider);
  1618. * // This will trigger a full page redirect away from your app
  1619. *
  1620. * // After returning from the redirect when your app initializes you can obtain the result
  1621. * const result = await getRedirectResult(auth);
  1622. * if (result) {
  1623. * // This is the signed-in user
  1624. * const user = result.user;
  1625. * // This gives you a Google Access Token.
  1626. * const credential = GoogleAuthProvider.credentialFromResult(result);
  1627. * const token = credential.accessToken;
  1628. * }
  1629. * ```
  1630. *
  1631. * @example
  1632. * ```javascript
  1633. * // Sign in using a popup.
  1634. * const provider = new GoogleAuthProvider();
  1635. * provider.addScope('profile');
  1636. * provider.addScope('email');
  1637. * const result = await signInWithPopup(auth, provider);
  1638. *
  1639. * // The signed-in user info.
  1640. * const user = result.user;
  1641. * // This gives you a Google Access Token.
  1642. * const credential = GoogleAuthProvider.credentialFromResult(result);
  1643. * const token = credential.accessToken;
  1644. * ```
  1645. *
  1646. * @public
  1647. */
  1648. export declare class GoogleAuthProvider extends BaseOAuthProvider {
  1649. /** Always set to {@link SignInMethod}.GOOGLE. */
  1650. static readonly GOOGLE_SIGN_IN_METHOD: 'google.com';
  1651. /** Always set to {@link ProviderId}.GOOGLE. */
  1652. static readonly PROVIDER_ID: 'google.com';
  1653. constructor();
  1654. /**
  1655. * Creates a credential for Google. At least one of ID token and access token is required.
  1656. *
  1657. * @example
  1658. * ```javascript
  1659. * // \`googleUser\` from the onsuccess Google Sign In callback.
  1660. * const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
  1661. * const result = await signInWithCredential(credential);
  1662. * ```
  1663. *
  1664. * @param idToken - Google ID token.
  1665. * @param accessToken - Google access token.
  1666. */
  1667. static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential;
  1668. /**
  1669. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  1670. *
  1671. * @param userCredential - The user credential.
  1672. */
  1673. static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
  1674. /**
  1675. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  1676. * thrown during a sign-in, link, or reauthenticate operation.
  1677. *
  1678. * @param userCredential - The user credential.
  1679. */
  1680. static credentialFromError(error: FirebaseError): OAuthCredential | null;
  1681. private static credentialFromTaggedObject;
  1682. }
  1683. /**
  1684. * Raw encoded JWT
  1685. *
  1686. */
  1687. declare type IdToken = string;
  1688. /**
  1689. * @internal
  1690. */
  1691. declare interface IdTokenMfaResponse extends IdTokenResponse {
  1692. mfaPendingCredential?: string;
  1693. mfaInfo?: MfaEnrollment[];
  1694. }
  1695. /**
  1696. * IdToken as returned by the API
  1697. *
  1698. * @internal
  1699. */
  1700. declare interface IdTokenResponse {
  1701. localId: string;
  1702. idToken?: IdToken;
  1703. refreshToken?: string;
  1704. expiresIn?: string;
  1705. providerId?: string;
  1706. displayName?: string | null;
  1707. isNewUser?: boolean;
  1708. kind?: IdTokenResponseKind;
  1709. photoUrl?: string | null;
  1710. rawUserInfo?: string;
  1711. screenName?: string | null;
  1712. }
  1713. /**
  1714. * The possible types of the `IdTokenResponse`
  1715. *
  1716. * @internal
  1717. */
  1718. declare const enum IdTokenResponseKind {
  1719. CreateAuthUri = "identitytoolkit#CreateAuthUriResponse",
  1720. DeleteAccount = "identitytoolkit#DeleteAccountResponse",
  1721. DownloadAccount = "identitytoolkit#DownloadAccountResponse",
  1722. EmailLinkSignin = "identitytoolkit#EmailLinkSigninResponse",
  1723. GetAccountInfo = "identitytoolkit#GetAccountInfoResponse",
  1724. GetOobConfirmationCode = "identitytoolkit#GetOobConfirmationCodeResponse",
  1725. GetRecaptchaParam = "identitytoolkit#GetRecaptchaParamResponse",
  1726. ResetPassword = "identitytoolkit#ResetPasswordResponse",
  1727. SetAccountInfo = "identitytoolkit#SetAccountInfoResponse",
  1728. SignupNewUser = "identitytoolkit#SignupNewUserResponse",
  1729. UploadAccount = "identitytoolkit#UploadAccountResponse",
  1730. VerifyAssertion = "identitytoolkit#VerifyAssertionResponse",
  1731. VerifyCustomToken = "identitytoolkit#VerifyCustomTokenResponse",
  1732. VerifyPassword = "identitytoolkit#VerifyPasswordResponse"
  1733. }
  1734. /**
  1735. * Interface representing ID token result obtained from {@link User.getIdTokenResult}.
  1736. *
  1737. * @remarks
  1738. * `IdTokenResult` contains the ID token JWT string and other helper properties for getting different data
  1739. * associated with the token as well as all the decoded payload claims.
  1740. *
  1741. * Note that these claims are not to be trusted as they are parsed client side. Only server side
  1742. * verification can guarantee the integrity of the token claims.
  1743. *
  1744. * @public
  1745. */
  1746. export declare interface IdTokenResult {
  1747. /**
  1748. * The authentication time formatted as a UTC string.
  1749. *
  1750. * @remarks
  1751. * This is the time the user authenticated (signed in) and not the time the token was refreshed.
  1752. */
  1753. authTime: string;
  1754. /** The ID token expiration time formatted as a UTC string. */
  1755. expirationTime: string;
  1756. /** The ID token issuance time formatted as a UTC string. */
  1757. issuedAtTime: string;
  1758. /**
  1759. * The sign-in provider through which the ID token was obtained (anonymous, custom, phone,
  1760. * password, etc).
  1761. *
  1762. * @remarks
  1763. * Note, this does not map to provider IDs.
  1764. */
  1765. signInProvider: string | null;
  1766. /**
  1767. * The type of second factor associated with this session, provided the user was multi-factor
  1768. * authenticated (eg. phone, etc).
  1769. */
  1770. signInSecondFactor: string | null;
  1771. /** The Firebase Auth ID token JWT string. */
  1772. token: string;
  1773. /**
  1774. * The entire payload claims of the ID token including the standard reserved claims as well as
  1775. * the custom claims.
  1776. */
  1777. claims: ParsedToken;
  1778. }
  1779. /**
  1780. * An implementation of {@link Persistence} of type `LOCAL` using `indexedDB`
  1781. * for the underlying storage.
  1782. *
  1783. * @public
  1784. */
  1785. export declare const indexedDBLocalPersistence: Persistence;
  1786. /**
  1787. * Initializes an {@link Auth} instance with fine-grained control over
  1788. * {@link Dependencies}.
  1789. *
  1790. * @remarks
  1791. *
  1792. * This function allows more control over the {@link Auth} instance than
  1793. * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
  1794. * the {@link Dependencies}. In general, `getAuth` is the easiest way to
  1795. * initialize Auth and works for most use cases. Use `initializeAuth` if you
  1796. * need control over which persistence layer is used, or to minimize bundle
  1797. * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
  1798. *
  1799. * For example, if your app only uses anonymous accounts and you only want
  1800. * accounts saved for the current session, initialize `Auth` with:
  1801. *
  1802. * ```js
  1803. * const auth = initializeAuth(app, {
  1804. * persistence: browserSessionPersistence,
  1805. * popupRedirectResolver: undefined,
  1806. * });
  1807. * ```
  1808. *
  1809. * @public
  1810. */
  1811. export declare function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth;
  1812. /**
  1813. * An implementation of {@link Persistence} of type 'NONE'.
  1814. *
  1815. * @public
  1816. */
  1817. export declare const inMemoryPersistence: Persistence;
  1818. /**
  1819. * Checks if an incoming link is a sign-in with email link suitable for {@link signInWithEmailLink}.
  1820. *
  1821. * @param auth - The {@link Auth} instance.
  1822. * @param emailLink - The link sent to the user's email address.
  1823. *
  1824. * @public
  1825. */
  1826. export declare function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean;
  1827. /**
  1828. * Links the user account with the given credentials.
  1829. *
  1830. * @remarks
  1831. * An {@link AuthProvider} can be used to generate the credential.
  1832. *
  1833. * @param user - The user.
  1834. * @param credential - The auth credential.
  1835. *
  1836. * @public
  1837. */
  1838. export declare function linkWithCredential(user: User, credential: AuthCredential): Promise<UserCredential>;
  1839. /**
  1840. * Links the user account with the given phone number.
  1841. *
  1842. * @param user - The user.
  1843. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
  1844. * @param appVerifier - The {@link ApplicationVerifier}.
  1845. *
  1846. * @public
  1847. */
  1848. export declare function linkWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
  1849. /**
  1850. * Links the authenticated provider to the user account using a pop-up based OAuth flow.
  1851. *
  1852. * @remarks
  1853. * If the linking is successful, the returned result will contain the user and the provider's credential.
  1854. *
  1855. *
  1856. * @example
  1857. * ```javascript
  1858. * // Sign in using some other provider.
  1859. * const result = await signInWithEmailAndPassword(auth, email, password);
  1860. * // Link using a popup.
  1861. * const provider = new FacebookAuthProvider();
  1862. * await linkWithPopup(result.user, provider);
  1863. * ```
  1864. *
  1865. * @param user - The user.
  1866. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  1867. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  1868. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  1869. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  1870. *
  1871. * @public
  1872. */
  1873. export declare function linkWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
  1874. /**
  1875. * Links the {@link OAuthProvider} to the user account using a full-page redirect flow.
  1876. * @remarks
  1877. * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
  1878. * Follow the [best practices](https://firebase.google.com/docs/auth/web/redirect-best-practices) when using {@link linkWithRedirect}.
  1879. *
  1880. * @example
  1881. * ```javascript
  1882. * // Sign in using some other provider.
  1883. * const result = await signInWithEmailAndPassword(auth, email, password);
  1884. * // Link using a redirect.
  1885. * const provider = new FacebookAuthProvider();
  1886. * await linkWithRedirect(result.user, provider);
  1887. * // This will trigger a full page redirect away from your app
  1888. *
  1889. * // After returning from the redirect when your app initializes you can obtain the result
  1890. * const result = await getRedirectResult(auth);
  1891. * ```
  1892. *
  1893. * @param user - The user.
  1894. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  1895. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  1896. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  1897. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  1898. *
  1899. *
  1900. * @public
  1901. */
  1902. export declare function linkWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
  1903. /**
  1904. * MfaEnrollment can be any subtype of BaseMfaEnrollment, currently only PhoneMfaEnrollment is supported
  1905. */
  1906. declare type MfaEnrollment = PhoneMfaEnrollment;
  1907. /**
  1908. * The {@link MultiFactorUser} corresponding to the user.
  1909. *
  1910. * @remarks
  1911. * This is used to access all multi-factor properties and operations related to the user.
  1912. *
  1913. * @param user - The user.
  1914. *
  1915. * @public
  1916. */
  1917. export declare function multiFactor(user: User): MultiFactorUser;
  1918. /**
  1919. * The base class for asserting ownership of a second factor.
  1920. *
  1921. * @remarks
  1922. * This is used to facilitate enrollment of a second factor on an existing user or sign-in of a
  1923. * user who already verified the first factor.
  1924. *
  1925. * @public
  1926. */
  1927. export declare interface MultiFactorAssertion {
  1928. /** The identifier of the second factor. */
  1929. readonly factorId: typeof FactorId[keyof typeof FactorId];
  1930. }
  1931. /**
  1932. * The error thrown when the user needs to provide a second factor to sign in successfully.
  1933. *
  1934. * @remarks
  1935. * The error code for this error is `auth/multi-factor-auth-required`.
  1936. *
  1937. * @example
  1938. * ```javascript
  1939. * let resolver;
  1940. * let multiFactorHints;
  1941. *
  1942. * signInWithEmailAndPassword(auth, email, password)
  1943. * .then((result) => {
  1944. * // User signed in. No 2nd factor challenge is needed.
  1945. * })
  1946. * .catch((error) => {
  1947. * if (error.code == 'auth/multi-factor-auth-required') {
  1948. * resolver = getMultiFactorResolver(auth, error);
  1949. * multiFactorHints = resolver.hints;
  1950. * } else {
  1951. * // Handle other errors.
  1952. * }
  1953. * });
  1954. *
  1955. * // Obtain a multiFactorAssertion by verifying the second factor.
  1956. *
  1957. * const userCredential = await resolver.resolveSignIn(multiFactorAssertion);
  1958. * ```
  1959. *
  1960. * @public
  1961. */
  1962. export declare interface MultiFactorError extends AuthError {
  1963. /** Details about the MultiFactorError. */
  1964. readonly customData: AuthError['customData'] & {
  1965. /**
  1966. * The type of operation (sign-in, linking, or re-authentication) that raised the error.
  1967. */
  1968. readonly operationType: typeof OperationType[keyof typeof OperationType];
  1969. };
  1970. }
  1971. /**
  1972. * A structure containing the information of a second factor entity.
  1973. *
  1974. * @public
  1975. */
  1976. export declare interface MultiFactorInfo {
  1977. /** The multi-factor enrollment ID. */
  1978. readonly uid: string;
  1979. /** The user friendly name of the current second factor. */
  1980. readonly displayName?: string | null;
  1981. /** The enrollment date of the second factor formatted as a UTC string. */
  1982. readonly enrollmentTime: string;
  1983. /** The identifier of the second factor. */
  1984. readonly factorId: typeof FactorId[keyof typeof FactorId];
  1985. }
  1986. /**
  1987. * The class used to facilitate recovery from {@link MultiFactorError} when a user needs to
  1988. * provide a second factor to sign in.
  1989. *
  1990. * @example
  1991. * ```javascript
  1992. * let resolver;
  1993. * let multiFactorHints;
  1994. *
  1995. * signInWithEmailAndPassword(auth, email, password)
  1996. * .then((result) => {
  1997. * // User signed in. No 2nd factor challenge is needed.
  1998. * })
  1999. * .catch((error) => {
  2000. * if (error.code == 'auth/multi-factor-auth-required') {
  2001. * resolver = getMultiFactorResolver(auth, error);
  2002. * // Show UI to let user select second factor.
  2003. * multiFactorHints = resolver.hints;
  2004. * } else {
  2005. * // Handle other errors.
  2006. * }
  2007. * });
  2008. *
  2009. * // The enrolled second factors that can be used to complete
  2010. * // sign-in are returned in the `MultiFactorResolver.hints` list.
  2011. * // UI needs to be presented to allow the user to select a second factor
  2012. * // from that list.
  2013. *
  2014. * const selectedHint = // ; selected from multiFactorHints
  2015. * const phoneAuthProvider = new PhoneAuthProvider(auth);
  2016. * const phoneInfoOptions = {
  2017. * multiFactorHint: selectedHint,
  2018. * session: resolver.session
  2019. * };
  2020. * const verificationId = phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
  2021. * // Store `verificationId` and show UI to let user enter verification code.
  2022. *
  2023. * // UI to enter verification code and continue.
  2024. * // Continue button click handler
  2025. * const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2026. * const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  2027. * const userCredential = await resolver.resolveSignIn(multiFactorAssertion);
  2028. * ```
  2029. *
  2030. * @public
  2031. */
  2032. export declare interface MultiFactorResolver {
  2033. /**
  2034. * The list of hints for the second factors needed to complete the sign-in for the current
  2035. * session.
  2036. */
  2037. readonly hints: MultiFactorInfo[];
  2038. /**
  2039. * The session identifier for the current sign-in flow, which can be used to complete the second
  2040. * factor sign-in.
  2041. */
  2042. readonly session: MultiFactorSession;
  2043. /**
  2044. * A helper function to help users complete sign in with a second factor using an
  2045. * {@link MultiFactorAssertion} confirming the user successfully completed the second factor
  2046. * challenge.
  2047. *
  2048. * @example
  2049. * ```javascript
  2050. * const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2051. * const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  2052. * const userCredential = await resolver.resolveSignIn(multiFactorAssertion);
  2053. * ```
  2054. *
  2055. * @param assertion - The multi-factor assertion to resolve sign-in with.
  2056. * @returns The promise that resolves with the user credential object.
  2057. */
  2058. resolveSignIn(assertion: MultiFactorAssertion): Promise<UserCredential>;
  2059. }
  2060. /**
  2061. * An interface defining the multi-factor session object used for enrolling a second factor on a
  2062. * user or helping sign in an enrolled user with a second factor.
  2063. *
  2064. * @public
  2065. */
  2066. export declare interface MultiFactorSession {
  2067. }
  2068. /**
  2069. * An interface that defines the multi-factor related properties and operations pertaining
  2070. * to a {@link User}.
  2071. *
  2072. * @public
  2073. */
  2074. export declare interface MultiFactorUser {
  2075. /** Returns a list of the user's enrolled second factors. */
  2076. readonly enrolledFactors: MultiFactorInfo[];
  2077. /**
  2078. * Returns the session identifier for a second factor enrollment operation. This is used to
  2079. * identify the user trying to enroll a second factor.
  2080. *
  2081. * @example
  2082. * ```javascript
  2083. * const multiFactorUser = multiFactor(auth.currentUser);
  2084. * const multiFactorSession = await multiFactorUser.getSession();
  2085. *
  2086. * // Send verification code.
  2087. * const phoneAuthProvider = new PhoneAuthProvider(auth);
  2088. * const phoneInfoOptions = {
  2089. * phoneNumber: phoneNumber,
  2090. * session: multiFactorSession
  2091. * };
  2092. * const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
  2093. *
  2094. * // Obtain verification code from user.
  2095. * const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2096. * const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  2097. * await multiFactorUser.enroll(multiFactorAssertion);
  2098. * ```
  2099. *
  2100. * @returns The promise that resolves with the {@link MultiFactorSession}.
  2101. */
  2102. getSession(): Promise<MultiFactorSession>;
  2103. /**
  2104. *
  2105. * Enrolls a second factor as identified by the {@link MultiFactorAssertion} for the
  2106. * user.
  2107. *
  2108. * @remarks
  2109. * On resolution, the user tokens are updated to reflect the change in the JWT payload.
  2110. * Accepts an additional display name parameter used to identify the second factor to the end
  2111. * user. Recent re-authentication is required for this operation to succeed. On successful
  2112. * enrollment, existing Firebase sessions (refresh tokens) are revoked. When a new factor is
  2113. * enrolled, an email notification is sent to the user’s email.
  2114. *
  2115. * @example
  2116. * ```javascript
  2117. * const multiFactorUser = multiFactor(auth.currentUser);
  2118. * const multiFactorSession = await multiFactorUser.getSession();
  2119. *
  2120. * // Send verification code.
  2121. * const phoneAuthProvider = new PhoneAuthProvider(auth);
  2122. * const phoneInfoOptions = {
  2123. * phoneNumber: phoneNumber,
  2124. * session: multiFactorSession
  2125. * };
  2126. * const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
  2127. *
  2128. * // Obtain verification code from user.
  2129. * const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2130. * const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
  2131. * await multiFactorUser.enroll(multiFactorAssertion);
  2132. * // Second factor enrolled.
  2133. * ```
  2134. *
  2135. * @param assertion - The multi-factor assertion to enroll with.
  2136. * @param displayName - The display name of the second factor.
  2137. */
  2138. enroll(assertion: MultiFactorAssertion, displayName?: string | null): Promise<void>;
  2139. /**
  2140. * Unenrolls the specified second factor.
  2141. *
  2142. * @remarks
  2143. * To specify the factor to remove, pass a {@link MultiFactorInfo} object (retrieved from
  2144. * {@link MultiFactorUser.enrolledFactors}) or the
  2145. * factor's UID string. Sessions are not revoked when the account is unenrolled. An email
  2146. * notification is likely to be sent to the user notifying them of the change. Recent
  2147. * re-authentication is required for this operation to succeed. When an existing factor is
  2148. * unenrolled, an email notification is sent to the user’s email.
  2149. *
  2150. * @example
  2151. * ```javascript
  2152. * const multiFactorUser = multiFactor(auth.currentUser);
  2153. * // Present user the option to choose which factor to unenroll.
  2154. * await multiFactorUser.unenroll(multiFactorUser.enrolledFactors[i])
  2155. * ```
  2156. *
  2157. * @param option - The multi-factor option to unenroll.
  2158. * @returns - A `Promise` which resolves when the unenroll operation is complete.
  2159. */
  2160. unenroll(option: MultiFactorInfo | string): Promise<void>;
  2161. }
  2162. declare type MutableUserInfo = {
  2163. -readonly [K in keyof UserInfo]: UserInfo[K];
  2164. };
  2165. export { NextFn }
  2166. /**
  2167. * Type definition for an event callback.
  2168. *
  2169. * @privateRemarks TODO(avolkovi): should we consolidate with Subscribe<T> since we're changing the API anyway?
  2170. *
  2171. * @public
  2172. */
  2173. export declare type NextOrObserver<T> = NextFn<T | null> | Observer<T | null>;
  2174. /**
  2175. * Represents the OAuth credentials returned by an {@link OAuthProvider}.
  2176. *
  2177. * @remarks
  2178. * Implementations specify the details about each auth provider's credential requirements.
  2179. *
  2180. * @public
  2181. */
  2182. export declare class OAuthCredential extends AuthCredential {
  2183. /**
  2184. * The OAuth ID token associated with the credential if it belongs to an OIDC provider,
  2185. * such as `google.com`.
  2186. * @readonly
  2187. */
  2188. idToken?: string;
  2189. /**
  2190. * The OAuth access token associated with the credential if it belongs to an
  2191. * {@link OAuthProvider}, such as `facebook.com`, `twitter.com`, etc.
  2192. * @readonly
  2193. */
  2194. accessToken?: string;
  2195. /**
  2196. * The OAuth access token secret associated with the credential if it belongs to an OAuth 1.0
  2197. * provider, such as `twitter.com`.
  2198. * @readonly
  2199. */
  2200. secret?: string;
  2201. private nonce?;
  2202. private pendingToken;
  2203. /** @internal */
  2204. static _fromParams(params: OAuthCredentialParams): OAuthCredential;
  2205. /** {@inheritdoc AuthCredential.toJSON} */
  2206. toJSON(): object;
  2207. /**
  2208. * Static method to deserialize a JSON representation of an object into an
  2209. * {@link AuthCredential}.
  2210. *
  2211. * @param json - Input can be either Object or the stringified representation of the object.
  2212. * When string is provided, JSON.parse would be called first.
  2213. *
  2214. * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
  2215. */
  2216. static fromJSON(json: string | object): OAuthCredential | null;
  2217. /** @internal */
  2218. _getIdTokenResponse(auth: AuthInternal): Promise<IdTokenResponse>;
  2219. /** @internal */
  2220. _linkToIdToken(auth: AuthInternal, idToken: string): Promise<IdTokenResponse>;
  2221. /** @internal */
  2222. _getReauthenticationResolver(auth: AuthInternal): Promise<IdTokenResponse>;
  2223. private buildRequest;
  2224. }
  2225. /**
  2226. * Defines the options for initializing an {@link OAuthCredential}.
  2227. *
  2228. * @remarks
  2229. * For ID tokens with nonce claim, the raw nonce has to also be provided.
  2230. *
  2231. * @public
  2232. */
  2233. export declare interface OAuthCredentialOptions {
  2234. /**
  2235. * The OAuth ID token used to initialize the {@link OAuthCredential}.
  2236. */
  2237. idToken?: string;
  2238. /**
  2239. * The OAuth access token used to initialize the {@link OAuthCredential}.
  2240. */
  2241. accessToken?: string;
  2242. /**
  2243. * The raw nonce associated with the ID token.
  2244. *
  2245. * @remarks
  2246. * It is required when an ID token with a nonce field is provided. The SHA-256 hash of the
  2247. * raw nonce must match the nonce field in the ID token.
  2248. */
  2249. rawNonce?: string;
  2250. }
  2251. declare interface OAuthCredentialParams {
  2252. idToken?: string | null;
  2253. accessToken?: string | null;
  2254. oauthToken?: string;
  2255. secret?: string;
  2256. oauthTokenSecret?: string;
  2257. nonce?: string;
  2258. pendingToken?: string;
  2259. providerId: string;
  2260. signInMethod: string;
  2261. }
  2262. /**
  2263. * Provider for generating generic {@link OAuthCredential}.
  2264. *
  2265. * @example
  2266. * ```javascript
  2267. * // Sign in using a redirect.
  2268. * const provider = new OAuthProvider('google.com');
  2269. * // Start a sign in process for an unauthenticated user.
  2270. * provider.addScope('profile');
  2271. * provider.addScope('email');
  2272. * await signInWithRedirect(auth, provider);
  2273. * // This will trigger a full page redirect away from your app
  2274. *
  2275. * // After returning from the redirect when your app initializes you can obtain the result
  2276. * const result = await getRedirectResult(auth);
  2277. * if (result) {
  2278. * // This is the signed-in user
  2279. * const user = result.user;
  2280. * // This gives you a OAuth Access Token for the provider.
  2281. * const credential = provider.credentialFromResult(auth, result);
  2282. * const token = credential.accessToken;
  2283. * }
  2284. * ```
  2285. *
  2286. * @example
  2287. * ```javascript
  2288. * // Sign in using a popup.
  2289. * const provider = new OAuthProvider('google.com');
  2290. * provider.addScope('profile');
  2291. * provider.addScope('email');
  2292. * const result = await signInWithPopup(auth, provider);
  2293. *
  2294. * // The signed-in user info.
  2295. * const user = result.user;
  2296. * // This gives you a OAuth Access Token for the provider.
  2297. * const credential = provider.credentialFromResult(auth, result);
  2298. * const token = credential.accessToken;
  2299. * ```
  2300. * @public
  2301. */
  2302. export declare class OAuthProvider extends BaseOAuthProvider {
  2303. /**
  2304. * Creates an {@link OAuthCredential} from a JSON string or a plain object.
  2305. * @param json - A plain object or a JSON string
  2306. */
  2307. static credentialFromJSON(json: object | string): OAuthCredential;
  2308. /**
  2309. * Creates a {@link OAuthCredential} from a generic OAuth provider's access token or ID token.
  2310. *
  2311. * @remarks
  2312. * The raw nonce is required when an ID token with a nonce field is provided. The SHA-256 hash of
  2313. * the raw nonce must match the nonce field in the ID token.
  2314. *
  2315. * @example
  2316. * ```javascript
  2317. * // `googleUser` from the onsuccess Google Sign In callback.
  2318. * // Initialize a generate OAuth provider with a `google.com` providerId.
  2319. * const provider = new OAuthProvider('google.com');
  2320. * const credential = provider.credential({
  2321. * idToken: googleUser.getAuthResponse().id_token,
  2322. * });
  2323. * const result = await signInWithCredential(credential);
  2324. * ```
  2325. *
  2326. * @param params - Either the options object containing the ID token, access token and raw nonce
  2327. * or the ID token string.
  2328. */
  2329. credential(params: OAuthCredentialOptions): OAuthCredential;
  2330. /** An internal credential method that accepts more permissive options */
  2331. private _credential;
  2332. /**
  2333. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  2334. *
  2335. * @param userCredential - The user credential.
  2336. */
  2337. static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
  2338. /**
  2339. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  2340. * thrown during a sign-in, link, or reauthenticate operation.
  2341. *
  2342. * @param userCredential - The user credential.
  2343. */
  2344. static credentialFromError(error: FirebaseError): OAuthCredential | null;
  2345. private static oauthCredentialFromTaggedObject;
  2346. }
  2347. /**
  2348. * Adds an observer for changes to the user's sign-in state.
  2349. *
  2350. * @remarks
  2351. * To keep the old behavior, see {@link onIdTokenChanged}.
  2352. *
  2353. * @param auth - The {@link Auth} instance.
  2354. * @param nextOrObserver - callback triggered on change.
  2355. * @param error - Deprecated. This callback is never triggered. Errors
  2356. * on signing in/out can be caught in promises returned from
  2357. * sign-in/sign-out functions.
  2358. * @param completed - Deprecated. This callback is never triggered.
  2359. *
  2360. * @public
  2361. */
  2362. export declare function onAuthStateChanged(auth: Auth, nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
  2363. /**
  2364. * Adds an observer for changes to the signed-in user's ID token.
  2365. *
  2366. * @remarks
  2367. * This includes sign-in, sign-out, and token refresh events.
  2368. *
  2369. * @param auth - The {@link Auth} instance.
  2370. * @param nextOrObserver - callback triggered on change.
  2371. * @param error - Deprecated. This callback is never triggered. Errors
  2372. * on signing in/out can be caught in promises returned from
  2373. * sign-in/sign-out functions.
  2374. * @param completed - Deprecated. This callback is never triggered.
  2375. *
  2376. * @public
  2377. */
  2378. export declare function onIdTokenChanged(auth: Auth, nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
  2379. /**
  2380. * Enumeration of supported operation types.
  2381. *
  2382. * @public
  2383. */
  2384. export declare const OperationType: {
  2385. /** Operation involving linking an additional provider to an already signed-in user. */
  2386. readonly LINK: "link";
  2387. /** Operation involving using a provider to reauthenticate an already signed-in user. */
  2388. readonly REAUTHENTICATE: "reauthenticate";
  2389. /** Operation involving signing in a user. */
  2390. readonly SIGN_IN: "signIn";
  2391. };
  2392. /**
  2393. * Parses the email action link string and returns an {@link ActionCodeURL} if
  2394. * the link is valid, otherwise returns null.
  2395. *
  2396. * @public
  2397. */
  2398. export declare function parseActionCodeURL(link: string): ActionCodeURL | null;
  2399. /**
  2400. * Interface representing a parsed ID token.
  2401. *
  2402. * @privateRemarks TODO(avolkovi): consolidate with parsed_token in implementation.
  2403. *
  2404. * @public
  2405. */
  2406. export declare interface ParsedToken {
  2407. /** Expiration time of the token. */
  2408. 'exp'?: string;
  2409. /** UID of the user. */
  2410. 'sub'?: string;
  2411. /** Time at which authentication was performed. */
  2412. 'auth_time'?: string;
  2413. /** Issuance time of the token. */
  2414. 'iat'?: string;
  2415. /** Firebase specific claims, containing the provider(s) used to authenticate the user. */
  2416. 'firebase'?: {
  2417. 'sign_in_provider'?: string;
  2418. 'sign_in_second_factor'?: string;
  2419. 'identities'?: Record<string, string>;
  2420. };
  2421. /** Map of any additional custom claims. */
  2422. [key: string]: any;
  2423. }
  2424. declare type PersistedBlob = Record<string, unknown>;
  2425. /**
  2426. * An interface covering the possible persistence mechanism types.
  2427. *
  2428. * @public
  2429. */
  2430. export declare interface Persistence {
  2431. /**
  2432. * Type of Persistence.
  2433. * - 'SESSION' is used for temporary persistence such as `sessionStorage`.
  2434. * - 'LOCAL' is used for long term persistence such as `localStorage` or `IndexedDB`.
  2435. * - 'NONE' is used for in-memory, or no persistence.
  2436. */
  2437. readonly type: 'SESSION' | 'LOCAL' | 'NONE';
  2438. }
  2439. /**
  2440. * Represents the credentials returned by {@link PhoneAuthProvider}.
  2441. *
  2442. * @public
  2443. */
  2444. export declare class PhoneAuthCredential extends AuthCredential {
  2445. private readonly params;
  2446. private constructor();
  2447. /** @internal */
  2448. static _fromVerification(verificationId: string, verificationCode: string): PhoneAuthCredential;
  2449. /** @internal */
  2450. static _fromTokenResponse(phoneNumber: string, temporaryProof: string): PhoneAuthCredential;
  2451. /** @internal */
  2452. _getIdTokenResponse(auth: AuthInternal): Promise<PhoneOrOauthTokenResponse>;
  2453. /** @internal */
  2454. _linkToIdToken(auth: AuthInternal, idToken: string): Promise<IdTokenResponse>;
  2455. /** @internal */
  2456. _getReauthenticationResolver(auth: AuthInternal): Promise<IdTokenResponse>;
  2457. /** @internal */
  2458. _makeVerificationRequest(): SignInWithPhoneNumberRequest;
  2459. /** {@inheritdoc AuthCredential.toJSON} */
  2460. toJSON(): object;
  2461. /** Generates a phone credential based on a plain object or a JSON string. */
  2462. static fromJSON(json: object | string): PhoneAuthCredential | null;
  2463. }
  2464. /**
  2465. * Provider for generating an {@link PhoneAuthCredential}.
  2466. *
  2467. * @example
  2468. * ```javascript
  2469. * // 'recaptcha-container' is the ID of an element in the DOM.
  2470. * const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
  2471. * const provider = new PhoneAuthProvider(auth);
  2472. * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
  2473. * // Obtain the verificationCode from the user.
  2474. * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2475. * const userCredential = await signInWithCredential(auth, phoneCredential);
  2476. * ```
  2477. *
  2478. * @public
  2479. */
  2480. export declare class PhoneAuthProvider {
  2481. /** Always set to {@link ProviderId}.PHONE. */
  2482. static readonly PROVIDER_ID: 'phone';
  2483. /** Always set to {@link SignInMethod}.PHONE. */
  2484. static readonly PHONE_SIGN_IN_METHOD: 'phone';
  2485. /** Always set to {@link ProviderId}.PHONE. */
  2486. readonly providerId: "phone";
  2487. private readonly auth;
  2488. /**
  2489. * @param auth - The Firebase {@link Auth} instance in which sign-ins should occur.
  2490. *
  2491. */
  2492. constructor(auth: Auth);
  2493. /**
  2494. *
  2495. * Starts a phone number authentication flow by sending a verification code to the given phone
  2496. * number.
  2497. *
  2498. * @example
  2499. * ```javascript
  2500. * const provider = new PhoneAuthProvider(auth);
  2501. * const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
  2502. * // Obtain verificationCode from the user.
  2503. * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2504. * const userCredential = await signInWithCredential(auth, authCredential);
  2505. * ```
  2506. *
  2507. * @example
  2508. * An alternative flow is provided using the `signInWithPhoneNumber` method.
  2509. * ```javascript
  2510. * const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
  2511. * // Obtain verificationCode from the user.
  2512. * const userCredential = confirmationResult.confirm(verificationCode);
  2513. * ```
  2514. *
  2515. * @param phoneInfoOptions - The user's {@link PhoneInfoOptions}. The phone number should be in
  2516. * E.164 format (e.g. +16505550101).
  2517. * @param applicationVerifier - For abuse prevention, this method also requires a
  2518. * {@link ApplicationVerifier}. This SDK includes a reCAPTCHA-based implementation,
  2519. * {@link RecaptchaVerifier}.
  2520. *
  2521. * @returns A Promise for a verification ID that can be passed to
  2522. * {@link PhoneAuthProvider.credential} to identify this flow..
  2523. */
  2524. verifyPhoneNumber(phoneOptions: PhoneInfoOptions | string, applicationVerifier: ApplicationVerifier): Promise<string>;
  2525. /**
  2526. * Creates a phone auth credential, given the verification ID from
  2527. * {@link PhoneAuthProvider.verifyPhoneNumber} and the code that was sent to the user's
  2528. * mobile device.
  2529. *
  2530. * @example
  2531. * ```javascript
  2532. * const provider = new PhoneAuthProvider(auth);
  2533. * const verificationId = provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
  2534. * // Obtain verificationCode from the user.
  2535. * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  2536. * const userCredential = signInWithCredential(auth, authCredential);
  2537. * ```
  2538. *
  2539. * @example
  2540. * An alternative flow is provided using the `signInWithPhoneNumber` method.
  2541. * ```javascript
  2542. * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
  2543. * // Obtain verificationCode from the user.
  2544. * const userCredential = await confirmationResult.confirm(verificationCode);
  2545. * ```
  2546. *
  2547. * @param verificationId - The verification ID returned from {@link PhoneAuthProvider.verifyPhoneNumber}.
  2548. * @param verificationCode - The verification code sent to the user's mobile device.
  2549. *
  2550. * @returns The auth provider credential.
  2551. */
  2552. static credential(verificationId: string, verificationCode: string): PhoneAuthCredential;
  2553. /**
  2554. * Generates an {@link AuthCredential} from a {@link UserCredential}.
  2555. * @param userCredential - The user credential.
  2556. */
  2557. static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
  2558. /**
  2559. * Returns an {@link AuthCredential} when passed an error.
  2560. *
  2561. * @remarks
  2562. *
  2563. * This method works for errors like
  2564. * `auth/account-exists-with-different-credentials`. This is useful for
  2565. * recovering when attempting to set a user's phone number but the number
  2566. * in question is already tied to another account. For example, the following
  2567. * code tries to update the current user's phone number, and if that
  2568. * fails, links the user with the account associated with that number:
  2569. *
  2570. * ```js
  2571. * const provider = new PhoneAuthProvider(auth);
  2572. * const verificationId = await provider.verifyPhoneNumber(number, verifier);
  2573. * try {
  2574. * const code = ''; // Prompt the user for the verification code
  2575. * await updatePhoneNumber(
  2576. * auth.currentUser,
  2577. * PhoneAuthProvider.credential(verificationId, code));
  2578. * } catch (e) {
  2579. * if ((e as FirebaseError)?.code === 'auth/account-exists-with-different-credential') {
  2580. * const cred = PhoneAuthProvider.credentialFromError(e);
  2581. * await linkWithCredential(auth.currentUser, cred);
  2582. * }
  2583. * }
  2584. *
  2585. * // At this point, auth.currentUser.phoneNumber === number.
  2586. * ```
  2587. *
  2588. * @param error - The error to generate a credential from.
  2589. */
  2590. static credentialFromError(error: FirebaseError): AuthCredential | null;
  2591. private static credentialFromTaggedObject;
  2592. }
  2593. /**
  2594. * The information required to verify the ownership of a phone number.
  2595. *
  2596. * @remarks
  2597. * The information that's required depends on whether you are doing single-factor sign-in,
  2598. * multi-factor enrollment or multi-factor sign-in.
  2599. *
  2600. * @public
  2601. */
  2602. export declare type PhoneInfoOptions = PhoneSingleFactorInfoOptions | PhoneMultiFactorEnrollInfoOptions | PhoneMultiFactorSignInInfoOptions;
  2603. /**
  2604. * An MFA provided by SMS verification
  2605. */
  2606. declare interface PhoneMfaEnrollment extends BaseMfaEnrollment {
  2607. phoneInfo: string;
  2608. }
  2609. /**
  2610. * The class for asserting ownership of a phone second factor. Provided by
  2611. * {@link PhoneMultiFactorGenerator.assertion}.
  2612. *
  2613. * @public
  2614. */
  2615. export declare interface PhoneMultiFactorAssertion extends MultiFactorAssertion {
  2616. }
  2617. /**
  2618. * Options used for enrolling a second factor.
  2619. *
  2620. * @public
  2621. */
  2622. export declare interface PhoneMultiFactorEnrollInfoOptions {
  2623. /** Phone number to send a verification code to. */
  2624. phoneNumber: string;
  2625. /** The {@link MultiFactorSession} obtained via {@link MultiFactorUser.getSession}. */
  2626. session: MultiFactorSession;
  2627. }
  2628. /**
  2629. * Provider for generating a {@link PhoneMultiFactorAssertion}.
  2630. *
  2631. * @public
  2632. */
  2633. export declare class PhoneMultiFactorGenerator {
  2634. private constructor();
  2635. /**
  2636. * Provides a {@link PhoneMultiFactorAssertion} to confirm ownership of the phone second factor.
  2637. *
  2638. * @param phoneAuthCredential - A credential provided by {@link PhoneAuthProvider.credential}.
  2639. * @returns A {@link PhoneMultiFactorAssertion} which can be used with
  2640. * {@link MultiFactorResolver.resolveSignIn}
  2641. */
  2642. static assertion(credential: PhoneAuthCredential): PhoneMultiFactorAssertion;
  2643. /**
  2644. * The identifier of the phone second factor: `phone`.
  2645. */
  2646. static FACTOR_ID: string;
  2647. }
  2648. /**
  2649. * The subclass of the {@link MultiFactorInfo} interface for phone number
  2650. * second factors. The `factorId` of this second factor is {@link FactorId}.PHONE.
  2651. * @public
  2652. */
  2653. export declare interface PhoneMultiFactorInfo extends MultiFactorInfo {
  2654. /** The phone number associated with the current second factor. */
  2655. readonly phoneNumber: string;
  2656. }
  2657. /**
  2658. * Options used for signing in with a second factor.
  2659. *
  2660. * @public
  2661. */
  2662. export declare interface PhoneMultiFactorSignInInfoOptions {
  2663. /**
  2664. * The {@link MultiFactorInfo} obtained via {@link MultiFactorResolver.hints}.
  2665. *
  2666. * One of `multiFactorHint` or `multiFactorUid` is required.
  2667. */
  2668. multiFactorHint?: MultiFactorInfo;
  2669. /**
  2670. * The uid of the second factor.
  2671. *
  2672. * One of `multiFactorHint` or `multiFactorUid` is required.
  2673. */
  2674. multiFactorUid?: string;
  2675. /** The {@link MultiFactorSession} obtained via {@link MultiFactorResolver.session}. */
  2676. session: MultiFactorSession;
  2677. }
  2678. /**
  2679. * @internal
  2680. */
  2681. declare type PhoneOrOauthTokenResponse = SignInWithPhoneNumberResponse | SignInWithIdpResponse | IdTokenResponse;
  2682. /**
  2683. * Options used for single-factor sign-in.
  2684. *
  2685. * @public
  2686. */
  2687. export declare interface PhoneSingleFactorInfoOptions {
  2688. /** Phone number to send a verification code to. */
  2689. phoneNumber: string;
  2690. }
  2691. /**
  2692. * A resolver used for handling DOM specific operations like {@link signInWithPopup}
  2693. * or {@link signInWithRedirect}.
  2694. *
  2695. * @public
  2696. */
  2697. export declare interface PopupRedirectResolver {
  2698. }
  2699. /**
  2700. * We need to mark this interface as internal explicitly to exclude it in the public typings, because
  2701. * it references AuthInternal which has a circular dependency with UserInternal.
  2702. *
  2703. * @internal
  2704. */
  2705. declare interface PopupRedirectResolverInternal extends PopupRedirectResolver {
  2706. _shouldInitProactively: boolean;
  2707. _initialize(auth: AuthInternal): Promise<EventManager>;
  2708. _openPopup(auth: AuthInternal, provider: AuthProvider, authType: AuthEventType, eventId?: string): Promise<AuthPopup>;
  2709. _openRedirect(auth: AuthInternal, provider: AuthProvider, authType: AuthEventType, eventId?: string): Promise<void | never>;
  2710. _isIframeWebStorageSupported(auth: AuthInternal, cb: (support: boolean) => unknown): void;
  2711. _redirectPersistence: Persistence;
  2712. _originValidation(auth: Auth): Promise<void>;
  2713. _completeRedirectFn: (auth: Auth, resolver: PopupRedirectResolver, bypassAuthState: boolean) => Promise<UserCredential | null>;
  2714. _overrideRedirectResult: (auth: AuthInternal, resultGetter: () => Promise<UserCredentialInternal | null>) => void;
  2715. }
  2716. /**
  2717. * A minimal error map with all verbose error messages stripped.
  2718. *
  2719. * See discussion at {@link AuthErrorMap}
  2720. *
  2721. * @public
  2722. */
  2723. export declare const prodErrorMap: AuthErrorMap;
  2724. /**
  2725. * Enumeration of supported providers.
  2726. *
  2727. * @public
  2728. */
  2729. export declare const ProviderId: {
  2730. /** Facebook provider ID */
  2731. readonly FACEBOOK: "facebook.com";
  2732. /** GitHub provider ID */
  2733. readonly GITHUB: "github.com";
  2734. /** Google provider ID */
  2735. readonly GOOGLE: "google.com";
  2736. /** Password provider */
  2737. readonly PASSWORD: "password";
  2738. /** Phone provider */
  2739. readonly PHONE: "phone";
  2740. /** Twitter provider ID */
  2741. readonly TWITTER: "twitter.com";
  2742. };
  2743. /**
  2744. * @license
  2745. * Copyright 2021 Google LLC
  2746. *
  2747. * Licensed under the Apache License, Version 2.0 (the "License");
  2748. * you may not use this file except in compliance with the License.
  2749. * You may obtain a copy of the License at
  2750. *
  2751. * http://www.apache.org/licenses/LICENSE-2.0
  2752. *
  2753. * Unless required by applicable law or agreed to in writing, software
  2754. * distributed under the License is distributed on an "AS IS" BASIS,
  2755. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2756. * See the License for the specific language governing permissions and
  2757. * limitations under the License.
  2758. */
  2759. /**
  2760. * Enumeration of supported providers.
  2761. * @internal
  2762. */
  2763. declare const enum ProviderId_2 {
  2764. /** @internal */
  2765. ANONYMOUS = "anonymous",
  2766. /** @internal */
  2767. CUSTOM = "custom",
  2768. /** Facebook provider ID */
  2769. FACEBOOK = "facebook.com",
  2770. /** @internal */
  2771. FIREBASE = "firebase",
  2772. /** GitHub provider ID */
  2773. GITHUB = "github.com",
  2774. /** Google provider ID */
  2775. GOOGLE = "google.com",
  2776. /** Password provider */
  2777. PASSWORD = "password",
  2778. /** Phone provider */
  2779. PHONE = "phone",
  2780. /** Twitter provider ID */
  2781. TWITTER = "twitter.com"
  2782. }
  2783. declare interface ProviderUserInfo {
  2784. providerId: string;
  2785. rawId?: string;
  2786. email?: string;
  2787. displayName?: string;
  2788. photoUrl?: string;
  2789. phoneNumber?: string;
  2790. }
  2791. /**
  2792. * Interface for a supplied `AsyncStorage`.
  2793. *
  2794. * @public
  2795. */
  2796. export declare interface ReactNativeAsyncStorage {
  2797. /**
  2798. * Persist an item in storage.
  2799. *
  2800. * @param key - storage key.
  2801. * @param value - storage value.
  2802. */
  2803. setItem(key: string, value: string): Promise<void>;
  2804. /**
  2805. * Retrieve an item from storage.
  2806. *
  2807. * @param key - storage key.
  2808. */
  2809. getItem(key: string): Promise<string | null>;
  2810. /**
  2811. * Remove an item from storage.
  2812. *
  2813. * @param key - storage key.
  2814. */
  2815. removeItem(key: string): Promise<void>;
  2816. }
  2817. /**
  2818. * Re-authenticates a user using a fresh credential.
  2819. *
  2820. * @remarks
  2821. * Use before operations such as {@link updatePassword} that require tokens from recent sign-in
  2822. * attempts. This method can be used to recover from a `CREDENTIAL_TOO_OLD_LOGIN_AGAIN` error.
  2823. *
  2824. * @param user - The user.
  2825. * @param credential - The auth credential.
  2826. *
  2827. * @public
  2828. */
  2829. export declare function reauthenticateWithCredential(user: User, credential: AuthCredential): Promise<UserCredential>;
  2830. /**
  2831. * Re-authenticates a user using a fresh phone credential.
  2832. *
  2833. * @remarks Use before operations such as {@link updatePassword} that require tokens from recent sign-in attempts.
  2834. *
  2835. * @param user - The user.
  2836. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
  2837. * @param appVerifier - The {@link ApplicationVerifier}.
  2838. *
  2839. * @public
  2840. */
  2841. export declare function reauthenticateWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
  2842. /**
  2843. * Reauthenticates the current user with the specified {@link OAuthProvider} using a pop-up based
  2844. * OAuth flow.
  2845. *
  2846. * @remarks
  2847. * If the reauthentication is successful, the returned result will contain the user and the
  2848. * provider's credential.
  2849. *
  2850. * @example
  2851. * ```javascript
  2852. * // Sign in using a popup.
  2853. * const provider = new FacebookAuthProvider();
  2854. * const result = await signInWithPopup(auth, provider);
  2855. * // Reauthenticate using a popup.
  2856. * await reauthenticateWithPopup(result.user, provider);
  2857. * ```
  2858. *
  2859. * @param user - The user.
  2860. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  2861. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  2862. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  2863. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  2864. *
  2865. * @public
  2866. */
  2867. export declare function reauthenticateWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
  2868. /**
  2869. * Reauthenticates the current user with the specified {@link OAuthProvider} using a full-page redirect flow.
  2870. * @remarks
  2871. * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
  2872. * Follow the [best practices](https://firebase.google.com/docs/auth/web/redirect-best-practices) when using {@link reauthenticateWithRedirect}.
  2873. *
  2874. * @example
  2875. * ```javascript
  2876. * // Sign in using a redirect.
  2877. * const provider = new FacebookAuthProvider();
  2878. * const result = await signInWithRedirect(auth, provider);
  2879. * // This will trigger a full page redirect away from your app
  2880. *
  2881. * // After returning from the redirect when your app initializes you can obtain the result
  2882. * const result = await getRedirectResult(auth);
  2883. * // Reauthenticate using a redirect.
  2884. * await reauthenticateWithRedirect(result.user, provider);
  2885. * // This will again trigger a full page redirect away from your app
  2886. *
  2887. * // After returning from the redirect when your app initializes you can obtain the result
  2888. * const result = await getRedirectResult(auth);
  2889. * ```
  2890. *
  2891. * @param user - The user.
  2892. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  2893. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  2894. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  2895. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  2896. *
  2897. * @public
  2898. */
  2899. export declare function reauthenticateWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
  2900. declare interface Recaptcha {
  2901. render: (container: HTMLElement, parameters: RecaptchaParameters) => number;
  2902. getResponse: (id: number) => string;
  2903. execute: (id: number) => unknown;
  2904. reset: (id: number) => unknown;
  2905. }
  2906. /**
  2907. * We need to mark this interface as internal explicitly to exclude it in the public typings, because
  2908. * it references AuthInternal which has a circular dependency with UserInternal.
  2909. *
  2910. * @internal
  2911. */
  2912. declare interface ReCaptchaLoader {
  2913. load(auth: AuthInternal, hl?: string): Promise<Recaptcha>;
  2914. clearedOneInstance(): void;
  2915. }
  2916. /**
  2917. * Interface representing reCAPTCHA parameters.
  2918. *
  2919. * See the [reCAPTCHA docs](https://developers.google.com/recaptcha/docs/display#render_param)
  2920. * for the list of accepted parameters. All parameters are accepted except for `sitekey`: Firebase Auth
  2921. * provisions a reCAPTCHA for each project and will configure the site key upon rendering.
  2922. *
  2923. * For an invisible reCAPTCHA, set the `size` key to `invisible`.
  2924. *
  2925. * @public
  2926. */
  2927. export declare interface RecaptchaParameters {
  2928. [key: string]: any;
  2929. }
  2930. /**
  2931. * An {@link https://www.google.com/recaptcha/ | reCAPTCHA}-based application verifier.
  2932. *
  2933. * @public
  2934. */
  2935. export declare class RecaptchaVerifier implements ApplicationVerifierInternal {
  2936. private readonly parameters;
  2937. /**
  2938. * The application verifier type.
  2939. *
  2940. * @remarks
  2941. * For a reCAPTCHA verifier, this is 'recaptcha'.
  2942. */
  2943. readonly type = "recaptcha";
  2944. private destroyed;
  2945. private widgetId;
  2946. private readonly container;
  2947. private readonly isInvisible;
  2948. private readonly tokenChangeListeners;
  2949. private renderPromise;
  2950. private readonly auth;
  2951. /** @internal */
  2952. readonly _recaptchaLoader: ReCaptchaLoader;
  2953. private recaptcha;
  2954. /**
  2955. *
  2956. * @param containerOrId - The reCAPTCHA container parameter.
  2957. *
  2958. * @remarks
  2959. * This has different meaning depending on whether the reCAPTCHA is hidden or visible. For a
  2960. * visible reCAPTCHA the container must be empty. If a string is used, it has to correspond to
  2961. * an element ID. The corresponding element must also must be in the DOM at the time of
  2962. * initialization.
  2963. *
  2964. * @param parameters - The optional reCAPTCHA parameters.
  2965. *
  2966. * @remarks
  2967. * Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for
  2968. * the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will
  2969. * configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value
  2970. * 'invisible'.
  2971. *
  2972. * @param authExtern - The corresponding Firebase {@link Auth} instance.
  2973. */
  2974. constructor(containerOrId: HTMLElement | string, parameters: RecaptchaParameters, authExtern: Auth);
  2975. /**
  2976. * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA token.
  2977. *
  2978. * @returns A Promise for the reCAPTCHA token.
  2979. */
  2980. verify(): Promise<string>;
  2981. /**
  2982. * Renders the reCAPTCHA widget on the page.
  2983. *
  2984. * @returns A Promise that resolves with the reCAPTCHA widget ID.
  2985. */
  2986. render(): Promise<number>;
  2987. /** @internal */
  2988. _reset(): void;
  2989. /**
  2990. * Clears the reCAPTCHA widget from the page and destroys the instance.
  2991. */
  2992. clear(): void;
  2993. private validateStartingState;
  2994. private makeTokenCallback;
  2995. private assertNotDestroyed;
  2996. private makeRenderPromise;
  2997. private init;
  2998. private getAssertedRecaptcha;
  2999. }
  3000. /**
  3001. * Reloads user account data, if signed in.
  3002. *
  3003. * @param user - The user.
  3004. *
  3005. * @public
  3006. */
  3007. export declare function reload(user: User): Promise<void>;
  3008. /**
  3009. * An {@link AuthProvider} for SAML.
  3010. *
  3011. * @public
  3012. */
  3013. export declare class SAMLAuthProvider extends FederatedAuthProvider {
  3014. /**
  3015. * Constructor. The providerId must start with "saml."
  3016. * @param providerId - SAML provider ID.
  3017. */
  3018. constructor(providerId: string);
  3019. /**
  3020. * Generates an {@link AuthCredential} from a {@link UserCredential} after a
  3021. * successful SAML flow completes.
  3022. *
  3023. * @remarks
  3024. *
  3025. * For example, to get an {@link AuthCredential}, you could write the
  3026. * following code:
  3027. *
  3028. * ```js
  3029. * const userCredential = await signInWithPopup(auth, samlProvider);
  3030. * const credential = SAMLAuthProvider.credentialFromResult(userCredential);
  3031. * ```
  3032. *
  3033. * @param userCredential - The user credential.
  3034. */
  3035. static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
  3036. /**
  3037. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  3038. * thrown during a sign-in, link, or reauthenticate operation.
  3039. *
  3040. * @param userCredential - The user credential.
  3041. */
  3042. static credentialFromError(error: FirebaseError): AuthCredential | null;
  3043. /**
  3044. * Creates an {@link AuthCredential} from a JSON string or a plain object.
  3045. * @param json - A plain object or a JSON string
  3046. */
  3047. static credentialFromJSON(json: string | object): AuthCredential;
  3048. private static samlCredentialFromTaggedObject;
  3049. }
  3050. /**
  3051. * Sends a verification email to a user.
  3052. *
  3053. * @remarks
  3054. * The verification process is completed by calling {@link applyActionCode}.
  3055. *
  3056. * @example
  3057. * ```javascript
  3058. * const actionCodeSettings = {
  3059. * url: 'https://www.example.com/?email=user@example.com',
  3060. * iOS: {
  3061. * bundleId: 'com.example.ios'
  3062. * },
  3063. * android: {
  3064. * packageName: 'com.example.android',
  3065. * installApp: true,
  3066. * minimumVersion: '12'
  3067. * },
  3068. * handleCodeInApp: true
  3069. * };
  3070. * await sendEmailVerification(user, actionCodeSettings);
  3071. * // Obtain code from the user.
  3072. * await applyActionCode(auth, code);
  3073. * ```
  3074. *
  3075. * @param user - The user.
  3076. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  3077. *
  3078. * @public
  3079. */
  3080. export declare function sendEmailVerification(user: User, actionCodeSettings?: ActionCodeSettings | null): Promise<void>;
  3081. /**
  3082. * Sends a password reset email to the given email address.
  3083. *
  3084. * @remarks
  3085. * To complete the password reset, call {@link confirmPasswordReset} with the code supplied in
  3086. * the email sent to the user, along with the new password specified by the user.
  3087. *
  3088. * @example
  3089. * ```javascript
  3090. * const actionCodeSettings = {
  3091. * url: 'https://www.example.com/?email=user@example.com',
  3092. * iOS: {
  3093. * bundleId: 'com.example.ios'
  3094. * },
  3095. * android: {
  3096. * packageName: 'com.example.android',
  3097. * installApp: true,
  3098. * minimumVersion: '12'
  3099. * },
  3100. * handleCodeInApp: true
  3101. * };
  3102. * await sendPasswordResetEmail(auth, 'user@example.com', actionCodeSettings);
  3103. * // Obtain code from user.
  3104. * await confirmPasswordReset('user@example.com', code);
  3105. * ```
  3106. *
  3107. * @param auth - The {@link Auth} instance.
  3108. * @param email - The user's email address.
  3109. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  3110. *
  3111. * @public
  3112. */
  3113. export declare function sendPasswordResetEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;
  3114. /**
  3115. * Sends a sign-in email link to the user with the specified email.
  3116. *
  3117. * @remarks
  3118. * The sign-in operation has to always be completed in the app unlike other out of band email
  3119. * actions (password reset and email verifications). This is because, at the end of the flow,
  3120. * the user is expected to be signed in and their Auth state persisted within the app.
  3121. *
  3122. * To complete sign in with the email link, call {@link signInWithEmailLink} with the email
  3123. * address and the email link supplied in the email sent to the user.
  3124. *
  3125. * @example
  3126. * ```javascript
  3127. * const actionCodeSettings = {
  3128. * url: 'https://www.example.com/?email=user@example.com',
  3129. * iOS: {
  3130. * bundleId: 'com.example.ios'
  3131. * },
  3132. * android: {
  3133. * packageName: 'com.example.android',
  3134. * installApp: true,
  3135. * minimumVersion: '12'
  3136. * },
  3137. * handleCodeInApp: true
  3138. * };
  3139. * await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
  3140. * // Obtain emailLink from the user.
  3141. * if(isSignInWithEmailLink(auth, emailLink)) {
  3142. * await signInWithEmailLink(auth, 'user@example.com', emailLink);
  3143. * }
  3144. * ```
  3145. *
  3146. * @param authInternal - The {@link Auth} instance.
  3147. * @param email - The user's email address.
  3148. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  3149. *
  3150. * @public
  3151. */
  3152. export declare function sendSignInLinkToEmail(auth: Auth, email: string, actionCodeSettings: ActionCodeSettings): Promise<void>;
  3153. /**
  3154. * Changes the type of persistence on the {@link Auth} instance for the currently saved
  3155. * `Auth` session and applies this type of persistence for future sign-in requests, including
  3156. * sign-in with redirect requests.
  3157. *
  3158. * @remarks
  3159. * This makes it easy for a user signing in to specify whether their session should be
  3160. * remembered or not. It also makes it easier to never persist the `Auth` state for applications
  3161. * that are shared by other users or have sensitive data.
  3162. *
  3163. * @example
  3164. * ```javascript
  3165. * setPersistence(auth, browserSessionPersistence);
  3166. * ```
  3167. *
  3168. * @param auth - The {@link Auth} instance.
  3169. * @param persistence - The {@link Persistence} to use.
  3170. * @returns A `Promise` that resolves once the persistence change has completed
  3171. *
  3172. * @public
  3173. */
  3174. export declare function setPersistence(auth: Auth, persistence: Persistence): Promise<void>;
  3175. /**
  3176. * Asynchronously signs in as an anonymous user.
  3177. *
  3178. * @remarks
  3179. * If there is already an anonymous user signed in, that user will be returned; otherwise, a
  3180. * new anonymous user identity will be created and returned.
  3181. *
  3182. * @param auth - The {@link Auth} instance.
  3183. *
  3184. * @public
  3185. */
  3186. export declare function signInAnonymously(auth: Auth): Promise<UserCredential>;
  3187. /**
  3188. * Enumeration of supported sign-in methods.
  3189. *
  3190. * @public
  3191. */
  3192. export declare const SignInMethod: {
  3193. /** Email link sign in method */
  3194. readonly EMAIL_LINK: "emailLink";
  3195. /** Email/password sign in method */
  3196. readonly EMAIL_PASSWORD: "password";
  3197. /** Facebook sign in method */
  3198. readonly FACEBOOK: "facebook.com";
  3199. /** GitHub sign in method */
  3200. readonly GITHUB: "github.com";
  3201. /** Google sign in method */
  3202. readonly GOOGLE: "google.com";
  3203. /** Phone sign in method */
  3204. readonly PHONE: "phone";
  3205. /** Twitter sign in method */
  3206. readonly TWITTER: "twitter.com";
  3207. };
  3208. /**
  3209. * Asynchronously signs in with the given credentials.
  3210. *
  3211. * @remarks
  3212. * An {@link AuthProvider} can be used to generate the credential.
  3213. *
  3214. * @param auth - The {@link Auth} instance.
  3215. * @param credential - The auth credential.
  3216. *
  3217. * @public
  3218. */
  3219. export declare function signInWithCredential(auth: Auth, credential: AuthCredential): Promise<UserCredential>;
  3220. /**
  3221. * Asynchronously signs in using a custom token.
  3222. *
  3223. * @remarks
  3224. * Custom tokens are used to integrate Firebase Auth with existing auth systems, and must
  3225. * be generated by an auth backend using the
  3226. * {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createcustomtoken | createCustomToken}
  3227. * method in the {@link https://firebase.google.com/docs/auth/admin | Admin SDK} .
  3228. *
  3229. * Fails with an error if the token is invalid, expired, or not accepted by the Firebase Auth service.
  3230. *
  3231. * @param auth - The {@link Auth} instance.
  3232. * @param customToken - The custom token to sign in with.
  3233. *
  3234. * @public
  3235. */
  3236. export declare function signInWithCustomToken(auth: Auth, customToken: string): Promise<UserCredential>;
  3237. /**
  3238. * Asynchronously signs in using an email and password.
  3239. *
  3240. * @remarks
  3241. * Fails with an error if the email address and password do not match.
  3242. *
  3243. * Note: The user's password is NOT the password used to access the user's email account. The
  3244. * email address serves as a unique identifier for the user, and the password is used to access
  3245. * the user's account in your Firebase project. See also: {@link createUserWithEmailAndPassword}.
  3246. *
  3247. * @param auth - The {@link Auth} instance.
  3248. * @param email - The users email address.
  3249. * @param password - The users password.
  3250. *
  3251. * @public
  3252. */
  3253. export declare function signInWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>;
  3254. /**
  3255. * Asynchronously signs in using an email and sign-in email link.
  3256. *
  3257. * @remarks
  3258. * If no link is passed, the link is inferred from the current URL.
  3259. *
  3260. * Fails with an error if the email address is invalid or OTP in email link expires.
  3261. *
  3262. * Note: Confirm the link is a sign-in email link before calling this method firebase.auth.Auth.isSignInWithEmailLink.
  3263. *
  3264. * @example
  3265. * ```javascript
  3266. * const actionCodeSettings = {
  3267. * url: 'https://www.example.com/?email=user@example.com',
  3268. * iOS: {
  3269. * bundleId: 'com.example.ios'
  3270. * },
  3271. * android: {
  3272. * packageName: 'com.example.android',
  3273. * installApp: true,
  3274. * minimumVersion: '12'
  3275. * },
  3276. * handleCodeInApp: true
  3277. * };
  3278. * await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
  3279. * // Obtain emailLink from the user.
  3280. * if(isSignInWithEmailLink(auth, emailLink)) {
  3281. * await signInWithEmailLink(auth, 'user@example.com', emailLink);
  3282. * }
  3283. * ```
  3284. *
  3285. * @param auth - The {@link Auth} instance.
  3286. * @param email - The user's email address.
  3287. * @param emailLink - The link sent to the user's email address.
  3288. *
  3289. * @public
  3290. */
  3291. export declare function signInWithEmailLink(auth: Auth, email: string, emailLink?: string): Promise<UserCredential>;
  3292. /**
  3293. * @internal
  3294. */
  3295. declare interface SignInWithIdpResponse extends IdTokenResponse {
  3296. oauthAccessToken?: string;
  3297. oauthTokenSecret?: string;
  3298. nonce?: string;
  3299. oauthIdToken?: string;
  3300. pendingToken?: string;
  3301. }
  3302. /**
  3303. * Asynchronously signs in using a phone number.
  3304. *
  3305. * @remarks
  3306. * This method sends a code via SMS to the given
  3307. * phone number, and returns a {@link ConfirmationResult}. After the user
  3308. * provides the code sent to their phone, call {@link ConfirmationResult.confirm}
  3309. * with the code to sign the user in.
  3310. *
  3311. * For abuse prevention, this method also requires a {@link ApplicationVerifier}.
  3312. * This SDK includes a reCAPTCHA-based implementation, {@link RecaptchaVerifier}.
  3313. * This function can work on other platforms that do not support the
  3314. * {@link RecaptchaVerifier} (like React Native), but you need to use a
  3315. * third-party {@link ApplicationVerifier} implementation.
  3316. *
  3317. * @example
  3318. * ```javascript
  3319. * // 'recaptcha-container' is the ID of an element in the DOM.
  3320. * const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
  3321. * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
  3322. * // Obtain a verificationCode from the user.
  3323. * const credential = await confirmationResult.confirm(verificationCode);
  3324. * ```
  3325. *
  3326. * @param auth - The {@link Auth} instance.
  3327. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
  3328. * @param appVerifier - The {@link ApplicationVerifier}.
  3329. *
  3330. * @public
  3331. */
  3332. export declare function signInWithPhoneNumber(auth: Auth, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
  3333. /**
  3334. * @internal
  3335. */
  3336. declare interface SignInWithPhoneNumberRequest {
  3337. temporaryProof?: string;
  3338. phoneNumber?: string;
  3339. sessionInfo?: string;
  3340. code?: string;
  3341. tenantId?: string;
  3342. }
  3343. /**
  3344. * @internal
  3345. */
  3346. declare interface SignInWithPhoneNumberResponse extends IdTokenResponse {
  3347. temporaryProof?: string;
  3348. phoneNumber?: string;
  3349. }
  3350. /**
  3351. * Authenticates a Firebase client using a popup-based OAuth authentication flow.
  3352. *
  3353. * @remarks
  3354. * If succeeds, returns the signed in user along with the provider's credential. If sign in was
  3355. * unsuccessful, returns an error object containing additional information about the error.
  3356. *
  3357. * @example
  3358. * ```javascript
  3359. * // Sign in using a popup.
  3360. * const provider = new FacebookAuthProvider();
  3361. * const result = await signInWithPopup(auth, provider);
  3362. *
  3363. * // The signed-in user info.
  3364. * const user = result.user;
  3365. * // This gives you a Facebook Access Token.
  3366. * const credential = provider.credentialFromResult(auth, result);
  3367. * const token = credential.accessToken;
  3368. * ```
  3369. *
  3370. * @param auth - The {@link Auth} instance.
  3371. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  3372. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  3373. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  3374. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  3375. *
  3376. *
  3377. * @public
  3378. */
  3379. export declare function signInWithPopup(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<UserCredential>;
  3380. /**
  3381. * Authenticates a Firebase client using a full-page redirect flow.
  3382. *
  3383. * @remarks
  3384. * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
  3385. * Follow the [best practices](https://firebase.google.com/docs/auth/web/redirect-best-practices) when using {@link signInWithRedirect}.
  3386. *
  3387. * @example
  3388. * ```javascript
  3389. * // Sign in using a redirect.
  3390. * const provider = new FacebookAuthProvider();
  3391. * // You can add additional scopes to the provider:
  3392. * provider.addScope('user_birthday');
  3393. * // Start a sign in process for an unauthenticated user.
  3394. * await signInWithRedirect(auth, provider);
  3395. * // This will trigger a full page redirect away from your app
  3396. *
  3397. * // After returning from the redirect when your app initializes you can obtain the result
  3398. * const result = await getRedirectResult(auth);
  3399. * if (result) {
  3400. * // This is the signed-in user
  3401. * const user = result.user;
  3402. * // This gives you a Facebook Access Token.
  3403. * const credential = provider.credentialFromResult(auth, result);
  3404. * const token = credential.accessToken;
  3405. * }
  3406. * // As this API can be used for sign-in, linking and reauthentication,
  3407. * // check the operationType to determine what triggered this redirect
  3408. * // operation.
  3409. * const operationType = result.operationType;
  3410. * ```
  3411. *
  3412. * @param auth - The {@link Auth} instance.
  3413. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
  3414. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
  3415. * @param resolver - An instance of {@link PopupRedirectResolver}, optional
  3416. * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
  3417. *
  3418. * @public
  3419. */
  3420. export declare function signInWithRedirect(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
  3421. /**
  3422. * Signs out the current user.
  3423. *
  3424. * @param auth - The {@link Auth} instance.
  3425. *
  3426. * @public
  3427. */
  3428. export declare function signOut(auth: Auth): Promise<void>;
  3429. /**
  3430. * We need to mark this class as internal explicitly to exclude it in the public typings, because
  3431. * it references AuthInternal which has a circular dependency with UserInternal.
  3432. *
  3433. * @internal
  3434. */
  3435. declare class StsTokenManager {
  3436. refreshToken: string | null;
  3437. accessToken: string | null;
  3438. expirationTime: number | null;
  3439. get isExpired(): boolean;
  3440. updateFromServerResponse(response: IdTokenResponse | FinalizeMfaResponse): void;
  3441. getToken(auth: AuthInternal, forceRefresh?: boolean): Promise<string | null>;
  3442. clearRefreshToken(): void;
  3443. private refresh;
  3444. private updateTokensAndExpiration;
  3445. static fromJSON(appName: string, object: PersistedBlob): StsTokenManager;
  3446. toJSON(): object;
  3447. _assign(stsTokenManager: StsTokenManager): void;
  3448. _clone(): StsTokenManager;
  3449. _performRefresh(): never;
  3450. }
  3451. /**
  3452. * @internal
  3453. */
  3454. declare interface TaggedWithTokenResponse {
  3455. _tokenResponse?: PhoneOrOauthTokenResponse;
  3456. }
  3457. /**
  3458. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.TWITTER.
  3459. *
  3460. * @example
  3461. * ```javascript
  3462. * // Sign in using a redirect.
  3463. * const provider = new TwitterAuthProvider();
  3464. * // Start a sign in process for an unauthenticated user.
  3465. * await signInWithRedirect(auth, provider);
  3466. * // This will trigger a full page redirect away from your app
  3467. *
  3468. * // After returning from the redirect when your app initializes you can obtain the result
  3469. * const result = await getRedirectResult(auth);
  3470. * if (result) {
  3471. * // This is the signed-in user
  3472. * const user = result.user;
  3473. * // This gives you a Twitter Access Token and Secret.
  3474. * const credential = TwitterAuthProvider.credentialFromResult(result);
  3475. * const token = credential.accessToken;
  3476. * const secret = credential.secret;
  3477. * }
  3478. * ```
  3479. *
  3480. * @example
  3481. * ```javascript
  3482. * // Sign in using a popup.
  3483. * const provider = new TwitterAuthProvider();
  3484. * const result = await signInWithPopup(auth, provider);
  3485. *
  3486. * // The signed-in user info.
  3487. * const user = result.user;
  3488. * // This gives you a Twitter Access Token and Secret.
  3489. * const credential = TwitterAuthProvider.credentialFromResult(result);
  3490. * const token = credential.accessToken;
  3491. * const secret = credential.secret;
  3492. * ```
  3493. *
  3494. * @public
  3495. */
  3496. export declare class TwitterAuthProvider extends BaseOAuthProvider {
  3497. /** Always set to {@link SignInMethod}.TWITTER. */
  3498. static readonly TWITTER_SIGN_IN_METHOD: 'twitter.com';
  3499. /** Always set to {@link ProviderId}.TWITTER. */
  3500. static readonly PROVIDER_ID: 'twitter.com';
  3501. constructor();
  3502. /**
  3503. * Creates a credential for Twitter.
  3504. *
  3505. * @param token - Twitter access token.
  3506. * @param secret - Twitter secret.
  3507. */
  3508. static credential(token: string, secret: string): OAuthCredential;
  3509. /**
  3510. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  3511. *
  3512. * @param userCredential - The user credential.
  3513. */
  3514. static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
  3515. /**
  3516. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  3517. * thrown during a sign-in, link, or reauthenticate operation.
  3518. *
  3519. * @param userCredential - The user credential.
  3520. */
  3521. static credentialFromError(error: FirebaseError): OAuthCredential | null;
  3522. private static credentialFromTaggedObject;
  3523. }
  3524. /**
  3525. * Unlinks a provider from a user account.
  3526. *
  3527. * @param user - The user.
  3528. * @param providerId - The provider to unlink.
  3529. *
  3530. * @public
  3531. */
  3532. export declare function unlink(user: User, providerId: string): Promise<User>;
  3533. export { Unsubscribe }
  3534. /**
  3535. * Asynchronously sets the provided user as {@link Auth.currentUser} on the
  3536. * {@link Auth} instance.
  3537. *
  3538. * @remarks
  3539. * A new instance copy of the user provided will be made and set as currentUser.
  3540. *
  3541. * This will trigger {@link onAuthStateChanged} and {@link onIdTokenChanged} listeners
  3542. * like other sign in methods.
  3543. *
  3544. * The operation fails with an error if the user to be updated belongs to a different Firebase
  3545. * project.
  3546. *
  3547. * @param auth - The {@link Auth} instance.
  3548. * @param user - The new {@link User}.
  3549. *
  3550. * @public
  3551. */
  3552. export declare function updateCurrentUser(auth: Auth, user: User | null): Promise<void>;
  3553. /**
  3554. * Updates the user's email address.
  3555. *
  3556. * @remarks
  3557. * An email will be sent to the original email address (if it was set) that allows to revoke the
  3558. * email address change, in order to protect them from account hijacking.
  3559. *
  3560. * Important: this is a security sensitive operation that requires the user to have recently signed
  3561. * in. If this requirement isn't met, ask the user to authenticate again and then call
  3562. * {@link reauthenticateWithCredential}.
  3563. *
  3564. * @param user - The user.
  3565. * @param newEmail - The new email address.
  3566. *
  3567. * @public
  3568. */
  3569. export declare function updateEmail(user: User, newEmail: string): Promise<void>;
  3570. /**
  3571. * Updates the user's password.
  3572. *
  3573. * @remarks
  3574. * Important: this is a security sensitive operation that requires the user to have recently signed
  3575. * in. If this requirement isn't met, ask the user to authenticate again and then call
  3576. * {@link reauthenticateWithCredential}.
  3577. *
  3578. * @param user - The user.
  3579. * @param newPassword - The new password.
  3580. *
  3581. * @public
  3582. */
  3583. export declare function updatePassword(user: User, newPassword: string): Promise<void>;
  3584. /**
  3585. * Updates the user's phone number.
  3586. *
  3587. * @example
  3588. * ```
  3589. * // 'recaptcha-container' is the ID of an element in the DOM.
  3590. * const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
  3591. * const provider = new PhoneAuthProvider(auth);
  3592. * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
  3593. * // Obtain the verificationCode from the user.
  3594. * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
  3595. * await updatePhoneNumber(user, phoneCredential);
  3596. * ```
  3597. *
  3598. * @param user - The user.
  3599. * @param credential - A credential authenticating the new phone number.
  3600. *
  3601. * @public
  3602. */
  3603. export declare function updatePhoneNumber(user: User, credential: PhoneAuthCredential): Promise<void>;
  3604. /**
  3605. * Updates a user's profile data.
  3606. *
  3607. * @param user - The user.
  3608. * @param profile - The profile's `displayName` and `photoURL` to update.
  3609. *
  3610. * @public
  3611. */
  3612. export declare function updateProfile(user: User, { displayName, photoURL: photoUrl }: {
  3613. displayName?: string | null;
  3614. photoURL?: string | null;
  3615. }): Promise<void>;
  3616. /**
  3617. * Sets the current language to the default device/browser preference.
  3618. *
  3619. * @param auth - The {@link Auth} instance.
  3620. *
  3621. * @public
  3622. */
  3623. export declare function useDeviceLanguage(auth: Auth): void;
  3624. /**
  3625. * A user account.
  3626. *
  3627. * @public
  3628. */
  3629. export declare interface User extends UserInfo {
  3630. /**
  3631. * Whether the email has been verified with {@link sendEmailVerification} and
  3632. * {@link applyActionCode}.
  3633. */
  3634. readonly emailVerified: boolean;
  3635. /**
  3636. * Whether the user is authenticated using the {@link ProviderId}.ANONYMOUS provider.
  3637. */
  3638. readonly isAnonymous: boolean;
  3639. /**
  3640. * Additional metadata around user creation and sign-in times.
  3641. */
  3642. readonly metadata: UserMetadata;
  3643. /**
  3644. * Additional per provider such as displayName and profile information.
  3645. */
  3646. readonly providerData: UserInfo[];
  3647. /**
  3648. * Refresh token used to reauthenticate the user. Avoid using this directly and prefer
  3649. * {@link User.getIdToken} to refresh the ID token instead.
  3650. */
  3651. readonly refreshToken: string;
  3652. /**
  3653. * The user's tenant ID.
  3654. *
  3655. * @remarks
  3656. * This is a read-only property, which indicates the tenant ID
  3657. * used to sign in the user. This is null if the user is signed in from the parent
  3658. * project.
  3659. *
  3660. * @example
  3661. * ```javascript
  3662. * // Set the tenant ID on Auth instance.
  3663. * auth.tenantId = 'TENANT_PROJECT_ID';
  3664. *
  3665. * // All future sign-in request now include tenant ID.
  3666. * const result = await signInWithEmailAndPassword(auth, email, password);
  3667. * // result.user.tenantId should be 'TENANT_PROJECT_ID'.
  3668. * ```
  3669. */
  3670. readonly tenantId: string | null;
  3671. /**
  3672. * Deletes and signs out the user.
  3673. *
  3674. * @remarks
  3675. * Important: this is a security-sensitive operation that requires the user to have recently
  3676. * signed in. If this requirement isn't met, ask the user to authenticate again and then call
  3677. * one of the reauthentication methods like {@link reauthenticateWithCredential}.
  3678. */
  3679. delete(): Promise<void>;
  3680. /**
  3681. * Returns a JSON Web Token (JWT) used to identify the user to a Firebase service.
  3682. *
  3683. * @remarks
  3684. * Returns the current token if it has not expired or if it will not expire in the next five
  3685. * minutes. Otherwise, this will refresh the token and return a new one.
  3686. *
  3687. * @param forceRefresh - Force refresh regardless of token expiration.
  3688. */
  3689. getIdToken(forceRefresh?: boolean): Promise<string>;
  3690. /**
  3691. * Returns a deserialized JSON Web Token (JWT) used to identitfy the user to a Firebase service.
  3692. *
  3693. * @remarks
  3694. * Returns the current token if it has not expired or if it will not expire in the next five
  3695. * minutes. Otherwise, this will refresh the token and return a new one.
  3696. *
  3697. * @param forceRefresh - Force refresh regardless of token expiration.
  3698. */
  3699. getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
  3700. /**
  3701. * Refreshes the user, if signed in.
  3702. */
  3703. reload(): Promise<void>;
  3704. /**
  3705. * Returns a JSON-serializable representation of this object.
  3706. *
  3707. * @returns A JSON-serializable representation of this object.
  3708. */
  3709. toJSON(): object;
  3710. }
  3711. /**
  3712. * A structure containing a {@link User}, the {@link OperationType}, and the provider ID.
  3713. *
  3714. * @remarks
  3715. * `operationType` could be {@link OperationType}.SIGN_IN for a sign-in operation,
  3716. * {@link OperationType}.LINK for a linking operation and {@link OperationType}.REAUTHENTICATE for
  3717. * a reauthentication operation.
  3718. *
  3719. * @public
  3720. */
  3721. export declare interface UserCredential {
  3722. /**
  3723. * The user authenticated by this credential.
  3724. */
  3725. user: User;
  3726. /**
  3727. * The provider which was used to authenticate the user.
  3728. */
  3729. providerId: string | null;
  3730. /**
  3731. * The type of operation which was used to authenticate the user (such as sign-in or link).
  3732. */
  3733. operationType: typeof OperationType[keyof typeof OperationType];
  3734. }
  3735. /**
  3736. * @internal
  3737. */
  3738. declare interface UserCredentialInternal extends UserCredential, TaggedWithTokenResponse {
  3739. user: UserInternal;
  3740. }
  3741. /**
  3742. * User profile information, visible only to the Firebase project's apps.
  3743. *
  3744. * @public
  3745. */
  3746. export declare interface UserInfo {
  3747. /**
  3748. * The display name of the user.
  3749. */
  3750. readonly displayName: string | null;
  3751. /**
  3752. * The email of the user.
  3753. */
  3754. readonly email: string | null;
  3755. /**
  3756. * The phone number normalized based on the E.164 standard (e.g. +16505550101) for the
  3757. * user.
  3758. *
  3759. * @remarks
  3760. * This is null if the user has no phone credential linked to the account.
  3761. */
  3762. readonly phoneNumber: string | null;
  3763. /**
  3764. * The profile photo URL of the user.
  3765. */
  3766. readonly photoURL: string | null;
  3767. /**
  3768. * The provider used to authenticate the user.
  3769. */
  3770. readonly providerId: string;
  3771. /**
  3772. * The user's unique ID, scoped to the project.
  3773. */
  3774. readonly uid: string;
  3775. }
  3776. /**
  3777. * UserInternal and AuthInternal reference each other, so both of them are included in the public typings.
  3778. * In order to exclude them, we mark them as internal explicitly.
  3779. *
  3780. * @internal
  3781. */
  3782. declare interface UserInternal extends User {
  3783. displayName: string | null;
  3784. email: string | null;
  3785. phoneNumber: string | null;
  3786. photoURL: string | null;
  3787. auth: AuthInternal;
  3788. providerId: ProviderId_2.FIREBASE;
  3789. refreshToken: string;
  3790. emailVerified: boolean;
  3791. tenantId: string | null;
  3792. providerData: MutableUserInfo[];
  3793. metadata: UserMetadata_2;
  3794. stsTokenManager: StsTokenManager;
  3795. _redirectEventId?: string;
  3796. _updateTokensIfNecessary(response: IdTokenResponse | FinalizeMfaResponse, reload?: boolean): Promise<void>;
  3797. _assign(user: UserInternal): void;
  3798. _clone(auth: AuthInternal): UserInternal;
  3799. _onReload: (cb: NextFn<APIUserInfo>) => void;
  3800. _notifyReloadListener: NextFn<APIUserInfo>;
  3801. _startProactiveRefresh: () => void;
  3802. _stopProactiveRefresh: () => void;
  3803. getIdToken(forceRefresh?: boolean): Promise<string>;
  3804. getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
  3805. reload(): Promise<void>;
  3806. delete(): Promise<void>;
  3807. toJSON(): PersistedBlob;
  3808. }
  3809. /**
  3810. * Interface representing a user's metadata.
  3811. *
  3812. * @public
  3813. */
  3814. export declare interface UserMetadata {
  3815. /** Time the user was created. */
  3816. readonly creationTime?: string;
  3817. /** Time the user last signed in. */
  3818. readonly lastSignInTime?: string;
  3819. }
  3820. declare class UserMetadata_2 implements UserMetadata {
  3821. private createdAt?;
  3822. private lastLoginAt?;
  3823. creationTime?: string;
  3824. lastSignInTime?: string;
  3825. constructor(createdAt?: string | number | undefined, lastLoginAt?: string | number | undefined);
  3826. private _initializeTime;
  3827. _copy(metadata: UserMetadata_2): void;
  3828. toJSON(): object;
  3829. }
  3830. /**
  3831. * User profile used in {@link AdditionalUserInfo}.
  3832. *
  3833. * @public
  3834. */
  3835. export declare type UserProfile = Record<string, unknown>;
  3836. /**
  3837. * Sends a verification email to a new email address.
  3838. *
  3839. * @remarks
  3840. * The user's email will be updated to the new one after being verified.
  3841. *
  3842. * If you have a custom email action handler, you can complete the verification process by calling
  3843. * {@link applyActionCode}.
  3844. *
  3845. * @example
  3846. * ```javascript
  3847. * const actionCodeSettings = {
  3848. * url: 'https://www.example.com/?email=user@example.com',
  3849. * iOS: {
  3850. * bundleId: 'com.example.ios'
  3851. * },
  3852. * android: {
  3853. * packageName: 'com.example.android',
  3854. * installApp: true,
  3855. * minimumVersion: '12'
  3856. * },
  3857. * handleCodeInApp: true
  3858. * };
  3859. * await verifyBeforeUpdateEmail(user, 'newemail@example.com', actionCodeSettings);
  3860. * // Obtain code from the user.
  3861. * await applyActionCode(auth, code);
  3862. * ```
  3863. *
  3864. * @param user - The user.
  3865. * @param newEmail - The new email address to be verified before update.
  3866. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  3867. *
  3868. * @public
  3869. */
  3870. export declare function verifyBeforeUpdateEmail(user: User, newEmail: string, actionCodeSettings?: ActionCodeSettings | null): Promise<void>;
  3871. /**
  3872. * Checks a password reset code sent to the user by email or other out-of-band mechanism.
  3873. *
  3874. * @returns the user's email address if valid.
  3875. *
  3876. * @param auth - The {@link Auth} instance.
  3877. * @param code - A verification code sent to the user.
  3878. *
  3879. * @public
  3880. */
  3881. export declare function verifyPasswordResetCode(auth: Auth, code: string): Promise<string>;
  3882. export { }