auth.d.ts 145 KB

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