auth-public.d.ts 128 KB

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