No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index-69e083b1.js 316KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430
  1. 'use strict';
  2. var tslib = require('tslib');
  3. var util = require('@firebase/util');
  4. var app = require('@firebase/app');
  5. var logger = require('@firebase/logger');
  6. var component = require('@firebase/component');
  7. var fetchImpl = require('node-fetch');
  8. function _interopNamespace(e) {
  9. if (e && e.__esModule) return e;
  10. var n = Object.create(null);
  11. if (e) {
  12. Object.keys(e).forEach(function (k) {
  13. if (k !== 'default') {
  14. var d = Object.getOwnPropertyDescriptor(e, k);
  15. Object.defineProperty(n, k, d.get ? d : {
  16. enumerable: true,
  17. get: function () { return e[k]; }
  18. });
  19. }
  20. });
  21. }
  22. n["default"] = e;
  23. return Object.freeze(n);
  24. }
  25. var fetchImpl__namespace = /*#__PURE__*/_interopNamespace(fetchImpl);
  26. /**
  27. * @license
  28. * Copyright 2021 Google LLC
  29. *
  30. * Licensed under the Apache License, Version 2.0 (the "License");
  31. * you may not use this file except in compliance with the License.
  32. * You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing, software
  37. * distributed under the License is distributed on an "AS IS" BASIS,
  38. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39. * See the License for the specific language governing permissions and
  40. * limitations under the License.
  41. */
  42. /**
  43. * An enum of factors that may be used for multifactor authentication.
  44. *
  45. * @public
  46. */
  47. var FactorId = {
  48. /** Phone as second factor */
  49. PHONE: 'phone'
  50. };
  51. /**
  52. * Enumeration of supported providers.
  53. *
  54. * @public
  55. */
  56. var ProviderId = {
  57. /** Facebook provider ID */
  58. FACEBOOK: 'facebook.com',
  59. /** GitHub provider ID */
  60. GITHUB: 'github.com',
  61. /** Google provider ID */
  62. GOOGLE: 'google.com',
  63. /** Password provider */
  64. PASSWORD: 'password',
  65. /** Phone provider */
  66. PHONE: 'phone',
  67. /** Twitter provider ID */
  68. TWITTER: 'twitter.com'
  69. };
  70. /**
  71. * Enumeration of supported sign-in methods.
  72. *
  73. * @public
  74. */
  75. var SignInMethod = {
  76. /** Email link sign in method */
  77. EMAIL_LINK: 'emailLink',
  78. /** Email/password sign in method */
  79. EMAIL_PASSWORD: 'password',
  80. /** Facebook sign in method */
  81. FACEBOOK: 'facebook.com',
  82. /** GitHub sign in method */
  83. GITHUB: 'github.com',
  84. /** Google sign in method */
  85. GOOGLE: 'google.com',
  86. /** Phone sign in method */
  87. PHONE: 'phone',
  88. /** Twitter sign in method */
  89. TWITTER: 'twitter.com'
  90. };
  91. /**
  92. * Enumeration of supported operation types.
  93. *
  94. * @public
  95. */
  96. var OperationType = {
  97. /** Operation involving linking an additional provider to an already signed-in user. */
  98. LINK: 'link',
  99. /** Operation involving using a provider to reauthenticate an already signed-in user. */
  100. REAUTHENTICATE: 'reauthenticate',
  101. /** Operation involving signing in a user. */
  102. SIGN_IN: 'signIn'
  103. };
  104. /**
  105. * An enumeration of the possible email action types.
  106. *
  107. * @public
  108. */
  109. var ActionCodeOperation = {
  110. /** The email link sign-in action. */
  111. EMAIL_SIGNIN: 'EMAIL_SIGNIN',
  112. /** The password reset action. */
  113. PASSWORD_RESET: 'PASSWORD_RESET',
  114. /** The email revocation action. */
  115. RECOVER_EMAIL: 'RECOVER_EMAIL',
  116. /** The revert second factor addition email action. */
  117. REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION',
  118. /** The revert second factor addition email action. */
  119. VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL',
  120. /** The email verification action. */
  121. VERIFY_EMAIL: 'VERIFY_EMAIL'
  122. };
  123. /**
  124. * @license
  125. * Copyright 2020 Google LLC
  126. *
  127. * Licensed under the Apache License, Version 2.0 (the "License");
  128. * you may not use this file except in compliance with the License.
  129. * You may obtain a copy of the License at
  130. *
  131. * http://www.apache.org/licenses/LICENSE-2.0
  132. *
  133. * Unless required by applicable law or agreed to in writing, software
  134. * distributed under the License is distributed on an "AS IS" BASIS,
  135. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  136. * See the License for the specific language governing permissions and
  137. * limitations under the License.
  138. */
  139. function _debugErrorMap() {
  140. var _a;
  141. return _a = {},
  142. _a["admin-restricted-operation" /* AuthErrorCode.ADMIN_ONLY_OPERATION */] = 'This operation is restricted to administrators only.',
  143. _a["argument-error" /* AuthErrorCode.ARGUMENT_ERROR */] = '',
  144. _a["app-not-authorized" /* AuthErrorCode.APP_NOT_AUTHORIZED */] = "This app, identified by the domain where it's hosted, is not " +
  145. 'authorized to use Firebase Authentication with the provided API key. ' +
  146. 'Review your key configuration in the Google API console.',
  147. _a["app-not-installed" /* AuthErrorCode.APP_NOT_INSTALLED */] = 'The requested mobile application corresponding to the identifier (' +
  148. 'Android package name or iOS bundle ID) provided is not installed on ' +
  149. 'this device.',
  150. _a["captcha-check-failed" /* AuthErrorCode.CAPTCHA_CHECK_FAILED */] = 'The reCAPTCHA response token provided is either invalid, expired, ' +
  151. 'already used or the domain associated with it does not match the list ' +
  152. 'of whitelisted domains.',
  153. _a["code-expired" /* AuthErrorCode.CODE_EXPIRED */] = 'The SMS code has expired. Please re-send the verification code to try ' +
  154. 'again.',
  155. _a["cordova-not-ready" /* AuthErrorCode.CORDOVA_NOT_READY */] = 'Cordova framework is not ready.',
  156. _a["cors-unsupported" /* AuthErrorCode.CORS_UNSUPPORTED */] = 'This browser is not supported.',
  157. _a["credential-already-in-use" /* AuthErrorCode.CREDENTIAL_ALREADY_IN_USE */] = 'This credential is already associated with a different user account.',
  158. _a["custom-token-mismatch" /* AuthErrorCode.CREDENTIAL_MISMATCH */] = 'The custom token corresponds to a different audience.',
  159. _a["requires-recent-login" /* AuthErrorCode.CREDENTIAL_TOO_OLD_LOGIN_AGAIN */] = 'This operation is sensitive and requires recent authentication. Log in ' +
  160. 'again before retrying this request.',
  161. _a["dependent-sdk-initialized-before-auth" /* AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH */] = 'Another Firebase SDK was initialized and is trying to use Auth before Auth is ' +
  162. 'initialized. Please be sure to call `initializeAuth` or `getAuth` before ' +
  163. 'starting any other Firebase SDK.',
  164. _a["dynamic-link-not-activated" /* AuthErrorCode.DYNAMIC_LINK_NOT_ACTIVATED */] = 'Please activate Dynamic Links in the Firebase Console and agree to the terms and ' +
  165. 'conditions.',
  166. _a["email-change-needs-verification" /* AuthErrorCode.EMAIL_CHANGE_NEEDS_VERIFICATION */] = 'Multi-factor users must always have a verified email.',
  167. _a["email-already-in-use" /* AuthErrorCode.EMAIL_EXISTS */] = 'The email address is already in use by another account.',
  168. _a["emulator-config-failed" /* AuthErrorCode.EMULATOR_CONFIG_FAILED */] = 'Auth instance has already been used to make a network call. Auth can ' +
  169. 'no longer be configured to use the emulator. Try calling ' +
  170. '"connectAuthEmulator()" sooner.',
  171. _a["expired-action-code" /* AuthErrorCode.EXPIRED_OOB_CODE */] = 'The action code has expired.',
  172. _a["cancelled-popup-request" /* AuthErrorCode.EXPIRED_POPUP_REQUEST */] = 'This operation has been cancelled due to another conflicting popup being opened.',
  173. _a["internal-error" /* AuthErrorCode.INTERNAL_ERROR */] = 'An internal AuthError has occurred.',
  174. _a["invalid-app-credential" /* AuthErrorCode.INVALID_APP_CREDENTIAL */] = 'The phone verification request contains an invalid application verifier.' +
  175. ' The reCAPTCHA token response is either invalid or expired.',
  176. _a["invalid-app-id" /* AuthErrorCode.INVALID_APP_ID */] = 'The mobile app identifier is not registed for the current project.',
  177. _a["invalid-user-token" /* AuthErrorCode.INVALID_AUTH */] = "This user's credential isn't valid for this project. This can happen " +
  178. "if the user's token has been tampered with, or if the user isn't for " +
  179. 'the project associated with this API key.',
  180. _a["invalid-auth-event" /* AuthErrorCode.INVALID_AUTH_EVENT */] = 'An internal AuthError has occurred.',
  181. _a["invalid-verification-code" /* AuthErrorCode.INVALID_CODE */] = 'The SMS verification code used to create the phone auth credential is ' +
  182. 'invalid. Please resend the verification code sms and be sure to use the ' +
  183. 'verification code provided by the user.',
  184. _a["invalid-continue-uri" /* AuthErrorCode.INVALID_CONTINUE_URI */] = 'The continue URL provided in the request is invalid.',
  185. _a["invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */] = 'The following Cordova plugins must be installed to enable OAuth sign-in: ' +
  186. 'cordova-plugin-buildinfo, cordova-universal-links-plugin, ' +
  187. 'cordova-plugin-browsertab, cordova-plugin-inappbrowser and ' +
  188. 'cordova-plugin-customurlscheme.',
  189. _a["invalid-custom-token" /* AuthErrorCode.INVALID_CUSTOM_TOKEN */] = 'The custom token format is incorrect. Please check the documentation.',
  190. _a["invalid-dynamic-link-domain" /* AuthErrorCode.INVALID_DYNAMIC_LINK_DOMAIN */] = 'The provided dynamic link domain is not configured or authorized for the current project.',
  191. _a["invalid-email" /* AuthErrorCode.INVALID_EMAIL */] = 'The email address is badly formatted.',
  192. _a["invalid-emulator-scheme" /* AuthErrorCode.INVALID_EMULATOR_SCHEME */] = 'Emulator URL must start with a valid scheme (http:// or https://).',
  193. _a["invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */] = 'Your API key is invalid, please check you have copied it correctly.',
  194. _a["invalid-cert-hash" /* AuthErrorCode.INVALID_CERT_HASH */] = 'The SHA-1 certificate hash provided is invalid.',
  195. _a["invalid-credential" /* AuthErrorCode.INVALID_IDP_RESPONSE */] = 'The supplied auth credential is malformed or has expired.',
  196. _a["invalid-message-payload" /* AuthErrorCode.INVALID_MESSAGE_PAYLOAD */] = 'The email template corresponding to this action contains invalid characters in its message. ' +
  197. 'Please fix by going to the Auth email templates section in the Firebase Console.',
  198. _a["invalid-multi-factor-session" /* AuthErrorCode.INVALID_MFA_SESSION */] = 'The request does not contain a valid proof of first factor successful sign-in.',
  199. _a["invalid-oauth-provider" /* AuthErrorCode.INVALID_OAUTH_PROVIDER */] = 'EmailAuthProvider is not supported for this operation. This operation ' +
  200. 'only supports OAuth providers.',
  201. _a["invalid-oauth-client-id" /* AuthErrorCode.INVALID_OAUTH_CLIENT_ID */] = 'The OAuth client ID provided is either invalid or does not match the ' +
  202. 'specified API key.',
  203. _a["unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */] = 'This domain is not authorized for OAuth operations for your Firebase ' +
  204. 'project. Edit the list of authorized domains from the Firebase console.',
  205. _a["invalid-action-code" /* AuthErrorCode.INVALID_OOB_CODE */] = 'The action code is invalid. This can happen if the code is malformed, ' +
  206. 'expired, or has already been used.',
  207. _a["wrong-password" /* AuthErrorCode.INVALID_PASSWORD */] = 'The password is invalid or the user does not have a password.',
  208. _a["invalid-persistence-type" /* AuthErrorCode.INVALID_PERSISTENCE */] = 'The specified persistence type is invalid. It can only be local, session or none.',
  209. _a["invalid-phone-number" /* AuthErrorCode.INVALID_PHONE_NUMBER */] = 'The format of the phone number provided is incorrect. Please enter the ' +
  210. 'phone number in a format that can be parsed into E.164 format. E.164 ' +
  211. 'phone numbers are written in the format [+][country code][subscriber ' +
  212. 'number including area code].',
  213. _a["invalid-provider-id" /* AuthErrorCode.INVALID_PROVIDER_ID */] = 'The specified provider ID is invalid.',
  214. _a["invalid-recipient-email" /* AuthErrorCode.INVALID_RECIPIENT_EMAIL */] = 'The email corresponding to this action failed to send as the provided ' +
  215. 'recipient email address is invalid.',
  216. _a["invalid-sender" /* AuthErrorCode.INVALID_SENDER */] = 'The email template corresponding to this action contains an invalid sender email or name. ' +
  217. 'Please fix by going to the Auth email templates section in the Firebase Console.',
  218. _a["invalid-verification-id" /* AuthErrorCode.INVALID_SESSION_INFO */] = 'The verification ID used to create the phone auth credential is invalid.',
  219. _a["invalid-tenant-id" /* AuthErrorCode.INVALID_TENANT_ID */] = "The Auth instance's tenant ID is invalid.",
  220. _a["login-blocked" /* AuthErrorCode.LOGIN_BLOCKED */] = 'Login blocked by user-provided method: {$originalMessage}',
  221. _a["missing-android-pkg-name" /* AuthErrorCode.MISSING_ANDROID_PACKAGE_NAME */] = 'An Android Package Name must be provided if the Android App is required to be installed.',
  222. _a["auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */] = 'Be sure to include authDomain when calling firebase.initializeApp(), ' +
  223. 'by following the instructions in the Firebase console.',
  224. _a["missing-app-credential" /* AuthErrorCode.MISSING_APP_CREDENTIAL */] = 'The phone verification request is missing an application verifier ' +
  225. 'assertion. A reCAPTCHA response token needs to be provided.',
  226. _a["missing-verification-code" /* AuthErrorCode.MISSING_CODE */] = 'The phone auth credential was created with an empty SMS verification code.',
  227. _a["missing-continue-uri" /* AuthErrorCode.MISSING_CONTINUE_URI */] = 'A continue URL must be provided in the request.',
  228. _a["missing-iframe-start" /* AuthErrorCode.MISSING_IFRAME_START */] = 'An internal AuthError has occurred.',
  229. _a["missing-ios-bundle-id" /* AuthErrorCode.MISSING_IOS_BUNDLE_ID */] = 'An iOS Bundle ID must be provided if an App Store ID is provided.',
  230. _a["missing-or-invalid-nonce" /* AuthErrorCode.MISSING_OR_INVALID_NONCE */] = 'The request does not contain a valid nonce. This can occur if the ' +
  231. 'SHA-256 hash of the provided raw nonce does not match the hashed nonce ' +
  232. 'in the ID token payload.',
  233. _a["missing-multi-factor-info" /* AuthErrorCode.MISSING_MFA_INFO */] = 'No second factor identifier is provided.',
  234. _a["missing-multi-factor-session" /* AuthErrorCode.MISSING_MFA_SESSION */] = 'The request is missing proof of first factor successful sign-in.',
  235. _a["missing-phone-number" /* AuthErrorCode.MISSING_PHONE_NUMBER */] = 'To send verification codes, provide a phone number for the recipient.',
  236. _a["missing-verification-id" /* AuthErrorCode.MISSING_SESSION_INFO */] = 'The phone auth credential was created with an empty verification ID.',
  237. _a["app-deleted" /* AuthErrorCode.MODULE_DESTROYED */] = 'This instance of FirebaseApp has been deleted.',
  238. _a["multi-factor-info-not-found" /* AuthErrorCode.MFA_INFO_NOT_FOUND */] = 'The user does not have a second factor matching the identifier provided.',
  239. _a["multi-factor-auth-required" /* AuthErrorCode.MFA_REQUIRED */] = 'Proof of ownership of a second factor is required to complete sign-in.',
  240. _a["account-exists-with-different-credential" /* AuthErrorCode.NEED_CONFIRMATION */] = 'An account already exists with the same email address but different ' +
  241. 'sign-in credentials. Sign in using a provider associated with this ' +
  242. 'email address.',
  243. _a["network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */] = 'A network AuthError (such as timeout, interrupted connection or unreachable host) has occurred.',
  244. _a["no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */] = 'An internal AuthError has occurred.',
  245. _a["no-such-provider" /* AuthErrorCode.NO_SUCH_PROVIDER */] = 'User was not linked to an account with the given provider.',
  246. _a["null-user" /* AuthErrorCode.NULL_USER */] = 'A null user object was provided as the argument for an operation which ' +
  247. 'requires a non-null user object.',
  248. _a["operation-not-allowed" /* AuthErrorCode.OPERATION_NOT_ALLOWED */] = 'The given sign-in provider is disabled for this Firebase project. ' +
  249. 'Enable it in the Firebase console, under the sign-in method tab of the ' +
  250. 'Auth section.',
  251. _a["operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */] = 'This operation is not supported in the environment this application is ' +
  252. 'running on. "location.protocol" must be http, https or chrome-extension' +
  253. ' and web storage must be enabled.',
  254. _a["popup-blocked" /* AuthErrorCode.POPUP_BLOCKED */] = 'Unable to establish a connection with the popup. It may have been blocked by the browser.',
  255. _a["popup-closed-by-user" /* AuthErrorCode.POPUP_CLOSED_BY_USER */] = 'The popup has been closed by the user before finalizing the operation.',
  256. _a["provider-already-linked" /* AuthErrorCode.PROVIDER_ALREADY_LINKED */] = 'User can only be linked to one identity for the given provider.',
  257. _a["quota-exceeded" /* AuthErrorCode.QUOTA_EXCEEDED */] = "The project's quota for this operation has been exceeded.",
  258. _a["redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */] = 'The redirect operation has been cancelled by the user before finalizing.',
  259. _a["redirect-operation-pending" /* AuthErrorCode.REDIRECT_OPERATION_PENDING */] = 'A redirect sign-in operation is already pending.',
  260. _a["rejected-credential" /* AuthErrorCode.REJECTED_CREDENTIAL */] = 'The request contains malformed or mismatching credentials.',
  261. _a["second-factor-already-in-use" /* AuthErrorCode.SECOND_FACTOR_ALREADY_ENROLLED */] = 'The second factor is already enrolled on this account.',
  262. _a["maximum-second-factor-count-exceeded" /* AuthErrorCode.SECOND_FACTOR_LIMIT_EXCEEDED */] = 'The maximum allowed number of second factors on a user has been exceeded.',
  263. _a["tenant-id-mismatch" /* AuthErrorCode.TENANT_ID_MISMATCH */] = "The provided tenant ID does not match the Auth instance's tenant ID",
  264. _a["timeout" /* AuthErrorCode.TIMEOUT */] = 'The operation has timed out.',
  265. _a["user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */] = "The user's credential is no longer valid. The user must sign in again.",
  266. _a["too-many-requests" /* AuthErrorCode.TOO_MANY_ATTEMPTS_TRY_LATER */] = 'We have blocked all requests from this device due to unusual activity. ' +
  267. 'Try again later.',
  268. _a["unauthorized-continue-uri" /* AuthErrorCode.UNAUTHORIZED_DOMAIN */] = 'The domain of the continue URL is not whitelisted. Please whitelist ' +
  269. 'the domain in the Firebase console.',
  270. _a["unsupported-first-factor" /* AuthErrorCode.UNSUPPORTED_FIRST_FACTOR */] = 'Enrolling a second factor or signing in with a multi-factor account requires sign-in with a supported first factor.',
  271. _a["unsupported-persistence-type" /* AuthErrorCode.UNSUPPORTED_PERSISTENCE */] = 'The current environment does not support the specified persistence type.',
  272. _a["unsupported-tenant-operation" /* AuthErrorCode.UNSUPPORTED_TENANT_OPERATION */] = 'This operation is not supported in a multi-tenant context.',
  273. _a["unverified-email" /* AuthErrorCode.UNVERIFIED_EMAIL */] = 'The operation requires a verified email.',
  274. _a["user-cancelled" /* AuthErrorCode.USER_CANCELLED */] = 'The user did not grant your application the permissions it requested.',
  275. _a["user-not-found" /* AuthErrorCode.USER_DELETED */] = 'There is no user record corresponding to this identifier. The user may ' +
  276. 'have been deleted.',
  277. _a["user-disabled" /* AuthErrorCode.USER_DISABLED */] = 'The user account has been disabled by an administrator.',
  278. _a["user-mismatch" /* AuthErrorCode.USER_MISMATCH */] = 'The supplied credentials do not correspond to the previously signed in user.',
  279. _a["user-signed-out" /* AuthErrorCode.USER_SIGNED_OUT */] = '',
  280. _a["weak-password" /* AuthErrorCode.WEAK_PASSWORD */] = 'The password must be 6 characters long or more.',
  281. _a["web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */] = 'This browser is not supported or 3rd party cookies and data may be disabled.',
  282. _a["already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */] = 'initializeAuth() has already been called with ' +
  283. 'different options. To avoid this error, call initializeAuth() with the ' +
  284. 'same options as when it was originally called, or call getAuth() to return the' +
  285. ' already initialized instance.',
  286. _a;
  287. }
  288. function _prodErrorMap() {
  289. var _a;
  290. // We will include this one message in the prod error map since by the very
  291. // nature of this error, developers will never be able to see the message
  292. // using the debugErrorMap (which is installed during auth initialization).
  293. return _a = {},
  294. _a["dependent-sdk-initialized-before-auth" /* AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH */] = 'Another Firebase SDK was initialized and is trying to use Auth before Auth is ' +
  295. 'initialized. Please be sure to call `initializeAuth` or `getAuth` before ' +
  296. 'starting any other Firebase SDK.',
  297. _a;
  298. }
  299. /**
  300. * A verbose error map with detailed descriptions for most error codes.
  301. *
  302. * See discussion at {@link AuthErrorMap}
  303. *
  304. * @public
  305. */
  306. var debugErrorMap = _debugErrorMap;
  307. /**
  308. * A minimal error map with all verbose error messages stripped.
  309. *
  310. * See discussion at {@link AuthErrorMap}
  311. *
  312. * @public
  313. */
  314. var prodErrorMap = _prodErrorMap;
  315. var _DEFAULT_AUTH_ERROR_FACTORY = new util.ErrorFactory('auth', 'Firebase', _prodErrorMap());
  316. /**
  317. * A map of potential `Auth` error codes, for easier comparison with errors
  318. * thrown by the SDK.
  319. *
  320. * @remarks
  321. * Note that you can't tree-shake individual keys
  322. * in the map, so by using the map you might substantially increase your
  323. * bundle size.
  324. *
  325. * @public
  326. */
  327. var AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
  328. ADMIN_ONLY_OPERATION: 'auth/admin-restricted-operation',
  329. ARGUMENT_ERROR: 'auth/argument-error',
  330. APP_NOT_AUTHORIZED: 'auth/app-not-authorized',
  331. APP_NOT_INSTALLED: 'auth/app-not-installed',
  332. CAPTCHA_CHECK_FAILED: 'auth/captcha-check-failed',
  333. CODE_EXPIRED: 'auth/code-expired',
  334. CORDOVA_NOT_READY: 'auth/cordova-not-ready',
  335. CORS_UNSUPPORTED: 'auth/cors-unsupported',
  336. CREDENTIAL_ALREADY_IN_USE: 'auth/credential-already-in-use',
  337. CREDENTIAL_MISMATCH: 'auth/custom-token-mismatch',
  338. CREDENTIAL_TOO_OLD_LOGIN_AGAIN: 'auth/requires-recent-login',
  339. DEPENDENT_SDK_INIT_BEFORE_AUTH: 'auth/dependent-sdk-initialized-before-auth',
  340. DYNAMIC_LINK_NOT_ACTIVATED: 'auth/dynamic-link-not-activated',
  341. EMAIL_CHANGE_NEEDS_VERIFICATION: 'auth/email-change-needs-verification',
  342. EMAIL_EXISTS: 'auth/email-already-in-use',
  343. EMULATOR_CONFIG_FAILED: 'auth/emulator-config-failed',
  344. EXPIRED_OOB_CODE: 'auth/expired-action-code',
  345. EXPIRED_POPUP_REQUEST: 'auth/cancelled-popup-request',
  346. INTERNAL_ERROR: 'auth/internal-error',
  347. INVALID_API_KEY: 'auth/invalid-api-key',
  348. INVALID_APP_CREDENTIAL: 'auth/invalid-app-credential',
  349. INVALID_APP_ID: 'auth/invalid-app-id',
  350. INVALID_AUTH: 'auth/invalid-user-token',
  351. INVALID_AUTH_EVENT: 'auth/invalid-auth-event',
  352. INVALID_CERT_HASH: 'auth/invalid-cert-hash',
  353. INVALID_CODE: 'auth/invalid-verification-code',
  354. INVALID_CONTINUE_URI: 'auth/invalid-continue-uri',
  355. INVALID_CORDOVA_CONFIGURATION: 'auth/invalid-cordova-configuration',
  356. INVALID_CUSTOM_TOKEN: 'auth/invalid-custom-token',
  357. INVALID_DYNAMIC_LINK_DOMAIN: 'auth/invalid-dynamic-link-domain',
  358. INVALID_EMAIL: 'auth/invalid-email',
  359. INVALID_EMULATOR_SCHEME: 'auth/invalid-emulator-scheme',
  360. INVALID_IDP_RESPONSE: 'auth/invalid-credential',
  361. INVALID_MESSAGE_PAYLOAD: 'auth/invalid-message-payload',
  362. INVALID_MFA_SESSION: 'auth/invalid-multi-factor-session',
  363. INVALID_OAUTH_CLIENT_ID: 'auth/invalid-oauth-client-id',
  364. INVALID_OAUTH_PROVIDER: 'auth/invalid-oauth-provider',
  365. INVALID_OOB_CODE: 'auth/invalid-action-code',
  366. INVALID_ORIGIN: 'auth/unauthorized-domain',
  367. INVALID_PASSWORD: 'auth/wrong-password',
  368. INVALID_PERSISTENCE: 'auth/invalid-persistence-type',
  369. INVALID_PHONE_NUMBER: 'auth/invalid-phone-number',
  370. INVALID_PROVIDER_ID: 'auth/invalid-provider-id',
  371. INVALID_RECIPIENT_EMAIL: 'auth/invalid-recipient-email',
  372. INVALID_SENDER: 'auth/invalid-sender',
  373. INVALID_SESSION_INFO: 'auth/invalid-verification-id',
  374. INVALID_TENANT_ID: 'auth/invalid-tenant-id',
  375. MFA_INFO_NOT_FOUND: 'auth/multi-factor-info-not-found',
  376. MFA_REQUIRED: 'auth/multi-factor-auth-required',
  377. MISSING_ANDROID_PACKAGE_NAME: 'auth/missing-android-pkg-name',
  378. MISSING_APP_CREDENTIAL: 'auth/missing-app-credential',
  379. MISSING_AUTH_DOMAIN: 'auth/auth-domain-config-required',
  380. MISSING_CODE: 'auth/missing-verification-code',
  381. MISSING_CONTINUE_URI: 'auth/missing-continue-uri',
  382. MISSING_IFRAME_START: 'auth/missing-iframe-start',
  383. MISSING_IOS_BUNDLE_ID: 'auth/missing-ios-bundle-id',
  384. MISSING_OR_INVALID_NONCE: 'auth/missing-or-invalid-nonce',
  385. MISSING_MFA_INFO: 'auth/missing-multi-factor-info',
  386. MISSING_MFA_SESSION: 'auth/missing-multi-factor-session',
  387. MISSING_PHONE_NUMBER: 'auth/missing-phone-number',
  388. MISSING_SESSION_INFO: 'auth/missing-verification-id',
  389. MODULE_DESTROYED: 'auth/app-deleted',
  390. NEED_CONFIRMATION: 'auth/account-exists-with-different-credential',
  391. NETWORK_REQUEST_FAILED: 'auth/network-request-failed',
  392. NULL_USER: 'auth/null-user',
  393. NO_AUTH_EVENT: 'auth/no-auth-event',
  394. NO_SUCH_PROVIDER: 'auth/no-such-provider',
  395. OPERATION_NOT_ALLOWED: 'auth/operation-not-allowed',
  396. OPERATION_NOT_SUPPORTED: 'auth/operation-not-supported-in-this-environment',
  397. POPUP_BLOCKED: 'auth/popup-blocked',
  398. POPUP_CLOSED_BY_USER: 'auth/popup-closed-by-user',
  399. PROVIDER_ALREADY_LINKED: 'auth/provider-already-linked',
  400. QUOTA_EXCEEDED: 'auth/quota-exceeded',
  401. REDIRECT_CANCELLED_BY_USER: 'auth/redirect-cancelled-by-user',
  402. REDIRECT_OPERATION_PENDING: 'auth/redirect-operation-pending',
  403. REJECTED_CREDENTIAL: 'auth/rejected-credential',
  404. SECOND_FACTOR_ALREADY_ENROLLED: 'auth/second-factor-already-in-use',
  405. SECOND_FACTOR_LIMIT_EXCEEDED: 'auth/maximum-second-factor-count-exceeded',
  406. TENANT_ID_MISMATCH: 'auth/tenant-id-mismatch',
  407. TIMEOUT: 'auth/timeout',
  408. TOKEN_EXPIRED: 'auth/user-token-expired',
  409. TOO_MANY_ATTEMPTS_TRY_LATER: 'auth/too-many-requests',
  410. UNAUTHORIZED_DOMAIN: 'auth/unauthorized-continue-uri',
  411. UNSUPPORTED_FIRST_FACTOR: 'auth/unsupported-first-factor',
  412. UNSUPPORTED_PERSISTENCE: 'auth/unsupported-persistence-type',
  413. UNSUPPORTED_TENANT_OPERATION: 'auth/unsupported-tenant-operation',
  414. UNVERIFIED_EMAIL: 'auth/unverified-email',
  415. USER_CANCELLED: 'auth/user-cancelled',
  416. USER_DELETED: 'auth/user-not-found',
  417. USER_DISABLED: 'auth/user-disabled',
  418. USER_MISMATCH: 'auth/user-mismatch',
  419. USER_SIGNED_OUT: 'auth/user-signed-out',
  420. WEAK_PASSWORD: 'auth/weak-password',
  421. WEB_STORAGE_UNSUPPORTED: 'auth/web-storage-unsupported',
  422. ALREADY_INITIALIZED: 'auth/already-initialized'
  423. };
  424. /**
  425. * @license
  426. * Copyright 2020 Google LLC
  427. *
  428. * Licensed under the Apache License, Version 2.0 (the "License");
  429. * you may not use this file except in compliance with the License.
  430. * You may obtain a copy of the License at
  431. *
  432. * http://www.apache.org/licenses/LICENSE-2.0
  433. *
  434. * Unless required by applicable law or agreed to in writing, software
  435. * distributed under the License is distributed on an "AS IS" BASIS,
  436. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  437. * See the License for the specific language governing permissions and
  438. * limitations under the License.
  439. */
  440. var logClient = new logger.Logger('@firebase/auth');
  441. function _logError(msg) {
  442. var args = [];
  443. for (var _i = 1; _i < arguments.length; _i++) {
  444. args[_i - 1] = arguments[_i];
  445. }
  446. if (logClient.logLevel <= logger.LogLevel.ERROR) {
  447. logClient.error.apply(logClient, tslib.__spreadArray(["Auth (".concat(app.SDK_VERSION, "): ").concat(msg)], args, false));
  448. }
  449. }
  450. /**
  451. * @license
  452. * Copyright 2020 Google LLC
  453. *
  454. * Licensed under the Apache License, Version 2.0 (the "License");
  455. * you may not use this file except in compliance with the License.
  456. * You may obtain a copy of the License at
  457. *
  458. * http://www.apache.org/licenses/LICENSE-2.0
  459. *
  460. * Unless required by applicable law or agreed to in writing, software
  461. * distributed under the License is distributed on an "AS IS" BASIS,
  462. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  463. * See the License for the specific language governing permissions and
  464. * limitations under the License.
  465. */
  466. function _fail(authOrCode) {
  467. var rest = [];
  468. for (var _i = 1; _i < arguments.length; _i++) {
  469. rest[_i - 1] = arguments[_i];
  470. }
  471. throw createErrorInternal.apply(void 0, tslib.__spreadArray([authOrCode], rest, false));
  472. }
  473. function _createError(authOrCode) {
  474. var rest = [];
  475. for (var _i = 1; _i < arguments.length; _i++) {
  476. rest[_i - 1] = arguments[_i];
  477. }
  478. return createErrorInternal.apply(void 0, tslib.__spreadArray([authOrCode], rest, false));
  479. }
  480. function _errorWithCustomMessage(auth, code, message) {
  481. var _a;
  482. var errorMap = tslib.__assign(tslib.__assign({}, prodErrorMap()), (_a = {}, _a[code] = message, _a));
  483. var factory = new util.ErrorFactory('auth', 'Firebase', errorMap);
  484. return factory.create(code, {
  485. appName: auth.name
  486. });
  487. }
  488. function createErrorInternal(authOrCode) {
  489. var _a;
  490. var rest = [];
  491. for (var _i = 1; _i < arguments.length; _i++) {
  492. rest[_i - 1] = arguments[_i];
  493. }
  494. if (typeof authOrCode !== 'string') {
  495. var code = rest[0];
  496. var fullParams = tslib.__spreadArray([], rest.slice(1), true);
  497. if (fullParams[0]) {
  498. fullParams[0].appName = authOrCode.name;
  499. }
  500. return (_a = authOrCode._errorFactory).create.apply(_a, tslib.__spreadArray([code], fullParams, false));
  501. }
  502. return _DEFAULT_AUTH_ERROR_FACTORY.create.apply(_DEFAULT_AUTH_ERROR_FACTORY, tslib.__spreadArray([authOrCode], rest, false));
  503. }
  504. function _assert(assertion, authOrCode) {
  505. var rest = [];
  506. for (var _i = 2; _i < arguments.length; _i++) {
  507. rest[_i - 2] = arguments[_i];
  508. }
  509. if (!assertion) {
  510. throw createErrorInternal.apply(void 0, tslib.__spreadArray([authOrCode], rest, false));
  511. }
  512. }
  513. /**
  514. * Unconditionally fails, throwing an internal error with the given message.
  515. *
  516. * @param failure type of failure encountered
  517. * @throws Error
  518. */
  519. function debugFail(failure) {
  520. // Log the failure in addition to throw an exception, just in case the
  521. // exception is swallowed.
  522. var message = "INTERNAL ASSERTION FAILED: " + failure;
  523. _logError(message);
  524. // NOTE: We don't use FirebaseError here because these are internal failures
  525. // that cannot be handled by the user. (Also it would create a circular
  526. // dependency between the error and assert modules which doesn't work.)
  527. throw new Error(message);
  528. }
  529. /**
  530. * Fails if the given assertion condition is false, throwing an Error with the
  531. * given message if it did.
  532. *
  533. * @param assertion
  534. * @param message
  535. */
  536. function debugAssert(assertion, message) {
  537. if (!assertion) {
  538. debugFail(message);
  539. }
  540. }
  541. /**
  542. * @license
  543. * Copyright 2020 Google LLC
  544. *
  545. * Licensed under the Apache License, Version 2.0 (the "License");
  546. * you may not use this file except in compliance with the License.
  547. * You may obtain a copy of the License at
  548. *
  549. * http://www.apache.org/licenses/LICENSE-2.0
  550. *
  551. * Unless required by applicable law or agreed to in writing, software
  552. * distributed under the License is distributed on an "AS IS" BASIS,
  553. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  554. * See the License for the specific language governing permissions and
  555. * limitations under the License.
  556. */
  557. var instanceCache = new Map();
  558. function _getInstance(cls) {
  559. debugAssert(cls instanceof Function, 'Expected a class definition');
  560. var instance = instanceCache.get(cls);
  561. if (instance) {
  562. debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
  563. return instance;
  564. }
  565. instance = new cls();
  566. instanceCache.set(cls, instance);
  567. return instance;
  568. }
  569. /**
  570. * @license
  571. * Copyright 2020 Google LLC
  572. *
  573. * Licensed under the Apache License, Version 2.0 (the "License");
  574. * you may not use this file except in compliance with the License.
  575. * You may obtain a copy of the License at
  576. *
  577. * http://www.apache.org/licenses/LICENSE-2.0
  578. *
  579. * Unless required by applicable law or agreed to in writing, software
  580. * distributed under the License is distributed on an "AS IS" BASIS,
  581. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  582. * See the License for the specific language governing permissions and
  583. * limitations under the License.
  584. */
  585. /**
  586. * Initializes an {@link Auth} instance with fine-grained control over
  587. * {@link Dependencies}.
  588. *
  589. * @remarks
  590. *
  591. * This function allows more control over the {@link Auth} instance than
  592. * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
  593. * the {@link Dependencies}. In general, `getAuth` is the easiest way to
  594. * initialize Auth and works for most use cases. Use `initializeAuth` if you
  595. * need control over which persistence layer is used, or to minimize bundle
  596. * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
  597. *
  598. * For example, if your app only uses anonymous accounts and you only want
  599. * accounts saved for the current session, initialize `Auth` with:
  600. *
  601. * ```js
  602. * const auth = initializeAuth(app, {
  603. * persistence: browserSessionPersistence,
  604. * popupRedirectResolver: undefined,
  605. * });
  606. * ```
  607. *
  608. * @public
  609. */
  610. function initializeAuth(app$1, deps) {
  611. var provider = app._getProvider(app$1, 'auth');
  612. if (provider.isInitialized()) {
  613. var auth_1 = provider.getImmediate();
  614. var initialOptions = provider.getOptions();
  615. if (util.deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
  616. return auth_1;
  617. }
  618. else {
  619. _fail(auth_1, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
  620. }
  621. }
  622. var auth = provider.initialize({ options: deps });
  623. return auth;
  624. }
  625. function _initializeAuthInstance(auth, deps) {
  626. var persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
  627. var hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
  628. if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
  629. auth._updateErrorMap(deps.errorMap);
  630. }
  631. // This promise is intended to float; auth initialization happens in the
  632. // background, meanwhile the auth object may be used by the app.
  633. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  634. auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
  635. }
  636. /**
  637. * @license
  638. * Copyright 2020 Google LLC
  639. *
  640. * Licensed under the Apache License, Version 2.0 (the "License");
  641. * you may not use this file except in compliance with the License.
  642. * You may obtain a copy of the License at
  643. *
  644. * http://www.apache.org/licenses/LICENSE-2.0
  645. *
  646. * Unless required by applicable law or agreed to in writing, software
  647. * distributed under the License is distributed on an "AS IS" BASIS,
  648. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  649. * See the License for the specific language governing permissions and
  650. * limitations under the License.
  651. */
  652. function _getCurrentUrl() {
  653. var _a;
  654. return (typeof self !== 'undefined' && ((_a = self.location) === null || _a === void 0 ? void 0 : _a.href)) || '';
  655. }
  656. function _isHttpOrHttps() {
  657. return _getCurrentScheme() === 'http:' || _getCurrentScheme() === 'https:';
  658. }
  659. function _getCurrentScheme() {
  660. var _a;
  661. return (typeof self !== 'undefined' && ((_a = self.location) === null || _a === void 0 ? void 0 : _a.protocol)) || null;
  662. }
  663. /**
  664. * @license
  665. * Copyright 2020 Google LLC
  666. *
  667. * Licensed under the Apache License, Version 2.0 (the "License");
  668. * you may not use this file except in compliance with the License.
  669. * You may obtain a copy of the License at
  670. *
  671. * http://www.apache.org/licenses/LICENSE-2.0
  672. *
  673. * Unless required by applicable law or agreed to in writing, software
  674. * distributed under the License is distributed on an "AS IS" BASIS,
  675. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  676. * See the License for the specific language governing permissions and
  677. * limitations under the License.
  678. */
  679. /**
  680. * Determine whether the browser is working online
  681. */
  682. function _isOnline() {
  683. if (typeof navigator !== 'undefined' &&
  684. navigator &&
  685. 'onLine' in navigator &&
  686. typeof navigator.onLine === 'boolean' &&
  687. // Apply only for traditional web apps and Chrome extensions.
  688. // This is especially true for Cordova apps which have unreliable
  689. // navigator.onLine behavior unless cordova-plugin-network-information is
  690. // installed which overwrites the native navigator.onLine value and
  691. // defines navigator.connection.
  692. (_isHttpOrHttps() || util.isBrowserExtension() || 'connection' in navigator)) {
  693. return navigator.onLine;
  694. }
  695. // If we can't determine the state, assume it is online.
  696. return true;
  697. }
  698. function _getUserLanguage() {
  699. if (typeof navigator === 'undefined') {
  700. return null;
  701. }
  702. var navigatorLanguage = navigator;
  703. return (
  704. // Most reliable, but only supported in Chrome/Firefox.
  705. (navigatorLanguage.languages && navigatorLanguage.languages[0]) ||
  706. // Supported in most browsers, but returns the language of the browser
  707. // UI, not the language set in browser settings.
  708. navigatorLanguage.language ||
  709. // Couldn't determine language.
  710. null);
  711. }
  712. /**
  713. * @license
  714. * Copyright 2020 Google LLC
  715. *
  716. * Licensed under the Apache License, Version 2.0 (the "License");
  717. * you may not use this file except in compliance with the License.
  718. * You may obtain a copy of the License at
  719. *
  720. * http://www.apache.org/licenses/LICENSE-2.0
  721. *
  722. * Unless required by applicable law or agreed to in writing, software
  723. * distributed under the License is distributed on an "AS IS" BASIS,
  724. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  725. * See the License for the specific language governing permissions and
  726. * limitations under the License.
  727. */
  728. /**
  729. * A structure to help pick between a range of long and short delay durations
  730. * depending on the current environment. In general, the long delay is used for
  731. * mobile environments whereas short delays are used for desktop environments.
  732. */
  733. var Delay = /** @class */ (function () {
  734. function Delay(shortDelay, longDelay) {
  735. this.shortDelay = shortDelay;
  736. this.longDelay = longDelay;
  737. // Internal error when improperly initialized.
  738. debugAssert(longDelay > shortDelay, 'Short delay should be less than long delay!');
  739. this.isMobile = util.isMobileCordova() || util.isReactNative();
  740. }
  741. Delay.prototype.get = function () {
  742. if (!_isOnline()) {
  743. // Pick the shorter timeout.
  744. return Math.min(5000 /* DelayMin.OFFLINE */, this.shortDelay);
  745. }
  746. // If running in a mobile environment, return the long delay, otherwise
  747. // return the short delay.
  748. // This could be improved in the future to dynamically change based on other
  749. // variables instead of just reading the current environment.
  750. return this.isMobile ? this.longDelay : this.shortDelay;
  751. };
  752. return Delay;
  753. }());
  754. /**
  755. * @license
  756. * Copyright 2020 Google LLC
  757. *
  758. * Licensed under the Apache License, Version 2.0 (the "License");
  759. * you may not use this file except in compliance with the License.
  760. * You may obtain a copy of the License at
  761. *
  762. * http://www.apache.org/licenses/LICENSE-2.0
  763. *
  764. * Unless required by applicable law or agreed to in writing, software
  765. * distributed under the License is distributed on an "AS IS" BASIS,
  766. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  767. * See the License for the specific language governing permissions and
  768. * limitations under the License.
  769. */
  770. function _emulatorUrl(config, path) {
  771. debugAssert(config.emulator, 'Emulator should always be set here');
  772. var url = config.emulator.url;
  773. if (!path) {
  774. return url;
  775. }
  776. return "".concat(url).concat(path.startsWith('/') ? path.slice(1) : path);
  777. }
  778. /**
  779. * @license
  780. * Copyright 2020 Google LLC
  781. *
  782. * Licensed under the Apache License, Version 2.0 (the "License");
  783. * you may not use this file except in compliance with the License.
  784. * You may obtain a copy of the License at
  785. *
  786. * http://www.apache.org/licenses/LICENSE-2.0
  787. *
  788. * Unless required by applicable law or agreed to in writing, software
  789. * distributed under the License is distributed on an "AS IS" BASIS,
  790. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  791. * See the License for the specific language governing permissions and
  792. * limitations under the License.
  793. */
  794. var FetchProvider = /** @class */ (function () {
  795. function FetchProvider() {
  796. }
  797. FetchProvider.initialize = function (fetchImpl, headersImpl, responseImpl) {
  798. this.fetchImpl = fetchImpl;
  799. if (headersImpl) {
  800. this.headersImpl = headersImpl;
  801. }
  802. if (responseImpl) {
  803. this.responseImpl = responseImpl;
  804. }
  805. };
  806. FetchProvider.fetch = function () {
  807. if (this.fetchImpl) {
  808. return this.fetchImpl;
  809. }
  810. if (typeof self !== 'undefined' && 'fetch' in self) {
  811. return self.fetch;
  812. }
  813. debugFail('Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
  814. };
  815. FetchProvider.headers = function () {
  816. if (this.headersImpl) {
  817. return this.headersImpl;
  818. }
  819. if (typeof self !== 'undefined' && 'Headers' in self) {
  820. return self.Headers;
  821. }
  822. debugFail('Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
  823. };
  824. FetchProvider.response = function () {
  825. if (this.responseImpl) {
  826. return this.responseImpl;
  827. }
  828. if (typeof self !== 'undefined' && 'Response' in self) {
  829. return self.Response;
  830. }
  831. debugFail('Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
  832. };
  833. return FetchProvider;
  834. }());
  835. /**
  836. * @license
  837. * Copyright 2020 Google LLC
  838. *
  839. * Licensed under the Apache License, Version 2.0 (the "License");
  840. * you may not use this file except in compliance with the License.
  841. * You may obtain a copy of the License at
  842. *
  843. * http://www.apache.org/licenses/LICENSE-2.0
  844. *
  845. * Unless required by applicable law or agreed to in writing, software
  846. * distributed under the License is distributed on an "AS IS" BASIS,
  847. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  848. * See the License for the specific language governing permissions and
  849. * limitations under the License.
  850. */
  851. var _a$1;
  852. /**
  853. * Map from errors returned by the server to errors to developer visible errors
  854. */
  855. var SERVER_ERROR_MAP = (_a$1 = {},
  856. // Custom token errors.
  857. _a$1["CREDENTIAL_MISMATCH" /* ServerError.CREDENTIAL_MISMATCH */] = "custom-token-mismatch" /* AuthErrorCode.CREDENTIAL_MISMATCH */,
  858. // This can only happen if the SDK sends a bad request.
  859. _a$1["MISSING_CUSTOM_TOKEN" /* ServerError.MISSING_CUSTOM_TOKEN */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  860. // Create Auth URI errors.
  861. _a$1["INVALID_IDENTIFIER" /* ServerError.INVALID_IDENTIFIER */] = "invalid-email" /* AuthErrorCode.INVALID_EMAIL */,
  862. // This can only happen if the SDK sends a bad request.
  863. _a$1["MISSING_CONTINUE_URI" /* ServerError.MISSING_CONTINUE_URI */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  864. // Sign in with email and password errors (some apply to sign up too).
  865. _a$1["INVALID_PASSWORD" /* ServerError.INVALID_PASSWORD */] = "wrong-password" /* AuthErrorCode.INVALID_PASSWORD */,
  866. // This can only happen if the SDK sends a bad request.
  867. _a$1["MISSING_PASSWORD" /* ServerError.MISSING_PASSWORD */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  868. // Sign up with email and password errors.
  869. _a$1["EMAIL_EXISTS" /* ServerError.EMAIL_EXISTS */] = "email-already-in-use" /* AuthErrorCode.EMAIL_EXISTS */,
  870. _a$1["PASSWORD_LOGIN_DISABLED" /* ServerError.PASSWORD_LOGIN_DISABLED */] = "operation-not-allowed" /* AuthErrorCode.OPERATION_NOT_ALLOWED */,
  871. // Verify assertion for sign in with credential errors:
  872. _a$1["INVALID_IDP_RESPONSE" /* ServerError.INVALID_IDP_RESPONSE */] = "invalid-credential" /* AuthErrorCode.INVALID_IDP_RESPONSE */,
  873. _a$1["INVALID_PENDING_TOKEN" /* ServerError.INVALID_PENDING_TOKEN */] = "invalid-credential" /* AuthErrorCode.INVALID_IDP_RESPONSE */,
  874. _a$1["FEDERATED_USER_ID_ALREADY_LINKED" /* ServerError.FEDERATED_USER_ID_ALREADY_LINKED */] = "credential-already-in-use" /* AuthErrorCode.CREDENTIAL_ALREADY_IN_USE */,
  875. // This can only happen if the SDK sends a bad request.
  876. _a$1["MISSING_REQ_TYPE" /* ServerError.MISSING_REQ_TYPE */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  877. // Send Password reset email errors:
  878. _a$1["EMAIL_NOT_FOUND" /* ServerError.EMAIL_NOT_FOUND */] = "user-not-found" /* AuthErrorCode.USER_DELETED */,
  879. _a$1["RESET_PASSWORD_EXCEED_LIMIT" /* ServerError.RESET_PASSWORD_EXCEED_LIMIT */] = "too-many-requests" /* AuthErrorCode.TOO_MANY_ATTEMPTS_TRY_LATER */,
  880. _a$1["EXPIRED_OOB_CODE" /* ServerError.EXPIRED_OOB_CODE */] = "expired-action-code" /* AuthErrorCode.EXPIRED_OOB_CODE */,
  881. _a$1["INVALID_OOB_CODE" /* ServerError.INVALID_OOB_CODE */] = "invalid-action-code" /* AuthErrorCode.INVALID_OOB_CODE */,
  882. // This can only happen if the SDK sends a bad request.
  883. _a$1["MISSING_OOB_CODE" /* ServerError.MISSING_OOB_CODE */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  884. // Operations that require ID token in request:
  885. _a$1["CREDENTIAL_TOO_OLD_LOGIN_AGAIN" /* ServerError.CREDENTIAL_TOO_OLD_LOGIN_AGAIN */] = "requires-recent-login" /* AuthErrorCode.CREDENTIAL_TOO_OLD_LOGIN_AGAIN */,
  886. _a$1["INVALID_ID_TOKEN" /* ServerError.INVALID_ID_TOKEN */] = "invalid-user-token" /* AuthErrorCode.INVALID_AUTH */,
  887. _a$1["TOKEN_EXPIRED" /* ServerError.TOKEN_EXPIRED */] = "user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */,
  888. _a$1["USER_NOT_FOUND" /* ServerError.USER_NOT_FOUND */] = "user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */,
  889. // Other errors.
  890. _a$1["TOO_MANY_ATTEMPTS_TRY_LATER" /* ServerError.TOO_MANY_ATTEMPTS_TRY_LATER */] = "too-many-requests" /* AuthErrorCode.TOO_MANY_ATTEMPTS_TRY_LATER */,
  891. // Phone Auth related errors.
  892. _a$1["INVALID_CODE" /* ServerError.INVALID_CODE */] = "invalid-verification-code" /* AuthErrorCode.INVALID_CODE */,
  893. _a$1["INVALID_SESSION_INFO" /* ServerError.INVALID_SESSION_INFO */] = "invalid-verification-id" /* AuthErrorCode.INVALID_SESSION_INFO */,
  894. _a$1["INVALID_TEMPORARY_PROOF" /* ServerError.INVALID_TEMPORARY_PROOF */] = "invalid-credential" /* AuthErrorCode.INVALID_IDP_RESPONSE */,
  895. _a$1["MISSING_SESSION_INFO" /* ServerError.MISSING_SESSION_INFO */] = "missing-verification-id" /* AuthErrorCode.MISSING_SESSION_INFO */,
  896. _a$1["SESSION_EXPIRED" /* ServerError.SESSION_EXPIRED */] = "code-expired" /* AuthErrorCode.CODE_EXPIRED */,
  897. // Other action code errors when additional settings passed.
  898. // MISSING_CONTINUE_URI is getting mapped to INTERNAL_ERROR above.
  899. // This is OK as this error will be caught by client side validation.
  900. _a$1["MISSING_ANDROID_PACKAGE_NAME" /* ServerError.MISSING_ANDROID_PACKAGE_NAME */] = "missing-android-pkg-name" /* AuthErrorCode.MISSING_ANDROID_PACKAGE_NAME */,
  901. _a$1["UNAUTHORIZED_DOMAIN" /* ServerError.UNAUTHORIZED_DOMAIN */] = "unauthorized-continue-uri" /* AuthErrorCode.UNAUTHORIZED_DOMAIN */,
  902. // getProjectConfig errors when clientId is passed.
  903. _a$1["INVALID_OAUTH_CLIENT_ID" /* ServerError.INVALID_OAUTH_CLIENT_ID */] = "invalid-oauth-client-id" /* AuthErrorCode.INVALID_OAUTH_CLIENT_ID */,
  904. // User actions (sign-up or deletion) disabled errors.
  905. _a$1["ADMIN_ONLY_OPERATION" /* ServerError.ADMIN_ONLY_OPERATION */] = "admin-restricted-operation" /* AuthErrorCode.ADMIN_ONLY_OPERATION */,
  906. // Multi factor related errors.
  907. _a$1["INVALID_MFA_PENDING_CREDENTIAL" /* ServerError.INVALID_MFA_PENDING_CREDENTIAL */] = "invalid-multi-factor-session" /* AuthErrorCode.INVALID_MFA_SESSION */,
  908. _a$1["MFA_ENROLLMENT_NOT_FOUND" /* ServerError.MFA_ENROLLMENT_NOT_FOUND */] = "multi-factor-info-not-found" /* AuthErrorCode.MFA_INFO_NOT_FOUND */,
  909. _a$1["MISSING_MFA_ENROLLMENT_ID" /* ServerError.MISSING_MFA_ENROLLMENT_ID */] = "missing-multi-factor-info" /* AuthErrorCode.MISSING_MFA_INFO */,
  910. _a$1["MISSING_MFA_PENDING_CREDENTIAL" /* ServerError.MISSING_MFA_PENDING_CREDENTIAL */] = "missing-multi-factor-session" /* AuthErrorCode.MISSING_MFA_SESSION */,
  911. _a$1["SECOND_FACTOR_EXISTS" /* ServerError.SECOND_FACTOR_EXISTS */] = "second-factor-already-in-use" /* AuthErrorCode.SECOND_FACTOR_ALREADY_ENROLLED */,
  912. _a$1["SECOND_FACTOR_LIMIT_EXCEEDED" /* ServerError.SECOND_FACTOR_LIMIT_EXCEEDED */] = "maximum-second-factor-count-exceeded" /* AuthErrorCode.SECOND_FACTOR_LIMIT_EXCEEDED */,
  913. // Blocking functions related errors.
  914. _a$1["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
  915. _a$1);
  916. /**
  917. * @license
  918. * Copyright 2020 Google LLC
  919. *
  920. * Licensed under the Apache License, Version 2.0 (the "License");
  921. * you may not use this file except in compliance with the License.
  922. * You may obtain a copy of the License at
  923. *
  924. * http://www.apache.org/licenses/LICENSE-2.0
  925. *
  926. * Unless required by applicable law or agreed to in writing, software
  927. * distributed under the License is distributed on an "AS IS" BASIS,
  928. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  929. * See the License for the specific language governing permissions and
  930. * limitations under the License.
  931. */
  932. var DEFAULT_API_TIMEOUT_MS = new Delay(30000, 60000);
  933. function _addTidIfNecessary(auth, request) {
  934. if (auth.tenantId && !request.tenantId) {
  935. return tslib.__assign(tslib.__assign({}, request), { tenantId: auth.tenantId });
  936. }
  937. return request;
  938. }
  939. function _performApiRequest(auth, method, path, request, customErrorMap) {
  940. if (customErrorMap === void 0) { customErrorMap = {}; }
  941. return tslib.__awaiter(this, void 0, void 0, function () {
  942. var _this = this;
  943. return tslib.__generator(this, function (_a) {
  944. return [2 /*return*/, _performFetchWithErrorHandling(auth, customErrorMap, function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  945. var body, params, query, headers;
  946. return tslib.__generator(this, function (_a) {
  947. switch (_a.label) {
  948. case 0:
  949. body = {};
  950. params = {};
  951. if (request) {
  952. if (method === "GET" /* HttpMethod.GET */) {
  953. params = request;
  954. }
  955. else {
  956. body = {
  957. body: JSON.stringify(request)
  958. };
  959. }
  960. }
  961. query = util.querystring(tslib.__assign({ key: auth.config.apiKey }, params)).slice(1);
  962. return [4 /*yield*/, auth._getAdditionalHeaders()];
  963. case 1:
  964. headers = _a.sent();
  965. headers["Content-Type" /* HttpHeader.CONTENT_TYPE */] = 'application/json';
  966. if (auth.languageCode) {
  967. headers["X-Firebase-Locale" /* HttpHeader.X_FIREBASE_LOCALE */] = auth.languageCode;
  968. }
  969. return [2 /*return*/, FetchProvider.fetch()(_getFinalTarget(auth, auth.config.apiHost, path, query), tslib.__assign({ method: method, headers: headers, referrerPolicy: 'no-referrer' }, body))];
  970. }
  971. });
  972. }); })];
  973. });
  974. });
  975. }
  976. function _performFetchWithErrorHandling(auth, customErrorMap, fetchFn) {
  977. return tslib.__awaiter(this, void 0, void 0, function () {
  978. var errorMap, networkTimeout, response, json, errorMessage, _a, serverErrorCode, serverErrorMessage, authError, e_1;
  979. return tslib.__generator(this, function (_b) {
  980. switch (_b.label) {
  981. case 0:
  982. auth._canInitEmulator = false;
  983. errorMap = tslib.__assign(tslib.__assign({}, SERVER_ERROR_MAP), customErrorMap);
  984. _b.label = 1;
  985. case 1:
  986. _b.trys.push([1, 4, , 5]);
  987. networkTimeout = new NetworkTimeout(auth);
  988. return [4 /*yield*/, Promise.race([
  989. fetchFn(),
  990. networkTimeout.promise
  991. ])];
  992. case 2:
  993. response = _b.sent();
  994. // If we've reached this point, the fetch succeeded and the networkTimeout
  995. // didn't throw; clear the network timeout delay so that Node won't hang
  996. networkTimeout.clearNetworkTimeout();
  997. return [4 /*yield*/, response.json()];
  998. case 3:
  999. json = _b.sent();
  1000. if ('needConfirmation' in json) {
  1001. throw _makeTaggedError(auth, "account-exists-with-different-credential" /* AuthErrorCode.NEED_CONFIRMATION */, json);
  1002. }
  1003. if (response.ok && !('errorMessage' in json)) {
  1004. return [2 /*return*/, json];
  1005. }
  1006. else {
  1007. errorMessage = response.ok ? json.errorMessage : json.error.message;
  1008. _a = errorMessage.split(' : '), serverErrorCode = _a[0], serverErrorMessage = _a[1];
  1009. if (serverErrorCode === "FEDERATED_USER_ID_ALREADY_LINKED" /* ServerError.FEDERATED_USER_ID_ALREADY_LINKED */) {
  1010. throw _makeTaggedError(auth, "credential-already-in-use" /* AuthErrorCode.CREDENTIAL_ALREADY_IN_USE */, json);
  1011. }
  1012. else if (serverErrorCode === "EMAIL_EXISTS" /* ServerError.EMAIL_EXISTS */) {
  1013. throw _makeTaggedError(auth, "email-already-in-use" /* AuthErrorCode.EMAIL_EXISTS */, json);
  1014. }
  1015. else if (serverErrorCode === "USER_DISABLED" /* ServerError.USER_DISABLED */) {
  1016. throw _makeTaggedError(auth, "user-disabled" /* AuthErrorCode.USER_DISABLED */, json);
  1017. }
  1018. authError = errorMap[serverErrorCode] ||
  1019. serverErrorCode
  1020. .toLowerCase()
  1021. .replace(/[_\s]+/g, '-');
  1022. if (serverErrorMessage) {
  1023. throw _errorWithCustomMessage(auth, authError, serverErrorMessage);
  1024. }
  1025. else {
  1026. _fail(auth, authError);
  1027. }
  1028. }
  1029. return [3 /*break*/, 5];
  1030. case 4:
  1031. e_1 = _b.sent();
  1032. if (e_1 instanceof util.FirebaseError) {
  1033. throw e_1;
  1034. }
  1035. _fail(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
  1036. return [3 /*break*/, 5];
  1037. case 5: return [2 /*return*/];
  1038. }
  1039. });
  1040. });
  1041. }
  1042. function _performSignInRequest(auth, method, path, request, customErrorMap) {
  1043. if (customErrorMap === void 0) { customErrorMap = {}; }
  1044. return tslib.__awaiter(this, void 0, void 0, function () {
  1045. var serverResponse;
  1046. return tslib.__generator(this, function (_a) {
  1047. switch (_a.label) {
  1048. case 0: return [4 /*yield*/, _performApiRequest(auth, method, path, request, customErrorMap)];
  1049. case 1:
  1050. serverResponse = (_a.sent());
  1051. if ('mfaPendingCredential' in serverResponse) {
  1052. _fail(auth, "multi-factor-auth-required" /* AuthErrorCode.MFA_REQUIRED */, {
  1053. _serverResponse: serverResponse
  1054. });
  1055. }
  1056. return [2 /*return*/, serverResponse];
  1057. }
  1058. });
  1059. });
  1060. }
  1061. function _getFinalTarget(auth, host, path, query) {
  1062. var base = "".concat(host).concat(path, "?").concat(query);
  1063. if (!auth.config.emulator) {
  1064. return "".concat(auth.config.apiScheme, "://").concat(base);
  1065. }
  1066. return _emulatorUrl(auth.config, base);
  1067. }
  1068. var NetworkTimeout = /** @class */ (function () {
  1069. function NetworkTimeout(auth) {
  1070. var _this = this;
  1071. this.auth = auth;
  1072. // Node timers and browser timers are fundamentally incompatible, but we
  1073. // don't care about the value here
  1074. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1075. this.timer = null;
  1076. this.promise = new Promise(function (_, reject) {
  1077. _this.timer = setTimeout(function () {
  1078. return reject(_createError(_this.auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */));
  1079. }, DEFAULT_API_TIMEOUT_MS.get());
  1080. });
  1081. }
  1082. NetworkTimeout.prototype.clearNetworkTimeout = function () {
  1083. clearTimeout(this.timer);
  1084. };
  1085. return NetworkTimeout;
  1086. }());
  1087. function _makeTaggedError(auth, code, response) {
  1088. var errorParams = {
  1089. appName: auth.name
  1090. };
  1091. if (response.email) {
  1092. errorParams.email = response.email;
  1093. }
  1094. if (response.phoneNumber) {
  1095. errorParams.phoneNumber = response.phoneNumber;
  1096. }
  1097. var error = _createError(auth, code, errorParams);
  1098. // We know customData is defined on error because errorParams is defined
  1099. error.customData._tokenResponse = response;
  1100. return error;
  1101. }
  1102. /**
  1103. * @license
  1104. * Copyright 2020 Google LLC
  1105. *
  1106. * Licensed under the Apache License, Version 2.0 (the "License");
  1107. * you may not use this file except in compliance with the License.
  1108. * You may obtain a copy of the License at
  1109. *
  1110. * http://www.apache.org/licenses/LICENSE-2.0
  1111. *
  1112. * Unless required by applicable law or agreed to in writing, software
  1113. * distributed under the License is distributed on an "AS IS" BASIS,
  1114. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1115. * See the License for the specific language governing permissions and
  1116. * limitations under the License.
  1117. */
  1118. function deleteAccount(auth, request) {
  1119. return tslib.__awaiter(this, void 0, void 0, function () {
  1120. return tslib.__generator(this, function (_a) {
  1121. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:delete" /* Endpoint.DELETE_ACCOUNT */, request)];
  1122. });
  1123. });
  1124. }
  1125. function deleteLinkedAccounts(auth, request) {
  1126. return tslib.__awaiter(this, void 0, void 0, function () {
  1127. return tslib.__generator(this, function (_a) {
  1128. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:update" /* Endpoint.SET_ACCOUNT_INFO */, request)];
  1129. });
  1130. });
  1131. }
  1132. function getAccountInfo(auth, request) {
  1133. return tslib.__awaiter(this, void 0, void 0, function () {
  1134. return tslib.__generator(this, function (_a) {
  1135. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:lookup" /* Endpoint.GET_ACCOUNT_INFO */, request)];
  1136. });
  1137. });
  1138. }
  1139. /**
  1140. * @license
  1141. * Copyright 2020 Google LLC
  1142. *
  1143. * Licensed under the Apache License, Version 2.0 (the "License");
  1144. * you may not use this file except in compliance with the License.
  1145. * You may obtain a copy of the License at
  1146. *
  1147. * http://www.apache.org/licenses/LICENSE-2.0
  1148. *
  1149. * Unless required by applicable law or agreed to in writing, software
  1150. * distributed under the License is distributed on an "AS IS" BASIS,
  1151. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1152. * See the License for the specific language governing permissions and
  1153. * limitations under the License.
  1154. */
  1155. function utcTimestampToDateString(utcTimestamp) {
  1156. if (!utcTimestamp) {
  1157. return undefined;
  1158. }
  1159. try {
  1160. // Convert to date object.
  1161. var date = new Date(Number(utcTimestamp));
  1162. // Test date is valid.
  1163. if (!isNaN(date.getTime())) {
  1164. // Convert to UTC date string.
  1165. return date.toUTCString();
  1166. }
  1167. }
  1168. catch (e) {
  1169. // Do nothing. undefined will be returned.
  1170. }
  1171. return undefined;
  1172. }
  1173. /**
  1174. * @license
  1175. * Copyright 2020 Google LLC
  1176. *
  1177. * Licensed under the Apache License, Version 2.0 (the "License");
  1178. * you may not use this file except in compliance with the License.
  1179. * You may obtain a copy of the License at
  1180. *
  1181. * http://www.apache.org/licenses/LICENSE-2.0
  1182. *
  1183. * Unless required by applicable law or agreed to in writing, software
  1184. * distributed under the License is distributed on an "AS IS" BASIS,
  1185. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1186. * See the License for the specific language governing permissions and
  1187. * limitations under the License.
  1188. */
  1189. /**
  1190. * Returns a JSON Web Token (JWT) used to identify the user to a Firebase service.
  1191. *
  1192. * @remarks
  1193. * Returns the current token if it has not expired or if it will not expire in the next five
  1194. * minutes. Otherwise, this will refresh the token and return a new one.
  1195. *
  1196. * @param user - The user.
  1197. * @param forceRefresh - Force refresh regardless of token expiration.
  1198. *
  1199. * @public
  1200. */
  1201. function getIdToken(user, forceRefresh) {
  1202. if (forceRefresh === void 0) { forceRefresh = false; }
  1203. return util.getModularInstance(user).getIdToken(forceRefresh);
  1204. }
  1205. /**
  1206. * Returns a deserialized JSON Web Token (JWT) used to identitfy the user to a Firebase service.
  1207. *
  1208. * @remarks
  1209. * Returns the current token if it has not expired or if it will not expire in the next five
  1210. * minutes. Otherwise, this will refresh the token and return a new one.
  1211. *
  1212. * @param user - The user.
  1213. * @param forceRefresh - Force refresh regardless of token expiration.
  1214. *
  1215. * @public
  1216. */
  1217. function getIdTokenResult(user, forceRefresh) {
  1218. if (forceRefresh === void 0) { forceRefresh = false; }
  1219. return tslib.__awaiter(this, void 0, void 0, function () {
  1220. var userInternal, token, claims, firebase, signInProvider;
  1221. return tslib.__generator(this, function (_a) {
  1222. switch (_a.label) {
  1223. case 0:
  1224. userInternal = util.getModularInstance(user);
  1225. return [4 /*yield*/, userInternal.getIdToken(forceRefresh)];
  1226. case 1:
  1227. token = _a.sent();
  1228. claims = _parseToken(token);
  1229. _assert(claims && claims.exp && claims.auth_time && claims.iat, userInternal.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1230. firebase = typeof claims.firebase === 'object' ? claims.firebase : undefined;
  1231. signInProvider = firebase === null || firebase === void 0 ? void 0 : firebase['sign_in_provider'];
  1232. return [2 /*return*/, {
  1233. claims: claims,
  1234. token: token,
  1235. authTime: utcTimestampToDateString(secondsStringToMilliseconds(claims.auth_time)),
  1236. issuedAtTime: utcTimestampToDateString(secondsStringToMilliseconds(claims.iat)),
  1237. expirationTime: utcTimestampToDateString(secondsStringToMilliseconds(claims.exp)),
  1238. signInProvider: signInProvider || null,
  1239. signInSecondFactor: (firebase === null || firebase === void 0 ? void 0 : firebase['sign_in_second_factor']) || null
  1240. }];
  1241. }
  1242. });
  1243. });
  1244. }
  1245. function secondsStringToMilliseconds(seconds) {
  1246. return Number(seconds) * 1000;
  1247. }
  1248. function _parseToken(token) {
  1249. var _a = token.split('.'), algorithm = _a[0], payload = _a[1], signature = _a[2];
  1250. if (algorithm === undefined ||
  1251. payload === undefined ||
  1252. signature === undefined) {
  1253. _logError('JWT malformed, contained fewer than 3 sections');
  1254. return null;
  1255. }
  1256. try {
  1257. var decoded = util.base64Decode(payload);
  1258. if (!decoded) {
  1259. _logError('Failed to decode base64 JWT payload');
  1260. return null;
  1261. }
  1262. return JSON.parse(decoded);
  1263. }
  1264. catch (e) {
  1265. _logError('Caught error parsing JWT payload as JSON', e === null || e === void 0 ? void 0 : e.toString());
  1266. return null;
  1267. }
  1268. }
  1269. /**
  1270. * Extract expiresIn TTL from a token by subtracting the expiration from the issuance.
  1271. */
  1272. function _tokenExpiresIn(token) {
  1273. var parsedToken = _parseToken(token);
  1274. _assert(parsedToken, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1275. _assert(typeof parsedToken.exp !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1276. _assert(typeof parsedToken.iat !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1277. return Number(parsedToken.exp) - Number(parsedToken.iat);
  1278. }
  1279. /**
  1280. * @license
  1281. * Copyright 2020 Google LLC
  1282. *
  1283. * Licensed under the Apache License, Version 2.0 (the "License");
  1284. * you may not use this file except in compliance with the License.
  1285. * You may obtain a copy of the License at
  1286. *
  1287. * http://www.apache.org/licenses/LICENSE-2.0
  1288. *
  1289. * Unless required by applicable law or agreed to in writing, software
  1290. * distributed under the License is distributed on an "AS IS" BASIS,
  1291. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1292. * See the License for the specific language governing permissions and
  1293. * limitations under the License.
  1294. */
  1295. function _logoutIfInvalidated(user, promise, bypassAuthState) {
  1296. if (bypassAuthState === void 0) { bypassAuthState = false; }
  1297. return tslib.__awaiter(this, void 0, void 0, function () {
  1298. var e_1;
  1299. return tslib.__generator(this, function (_a) {
  1300. switch (_a.label) {
  1301. case 0:
  1302. if (bypassAuthState) {
  1303. return [2 /*return*/, promise];
  1304. }
  1305. _a.label = 1;
  1306. case 1:
  1307. _a.trys.push([1, 3, , 6]);
  1308. return [4 /*yield*/, promise];
  1309. case 2: return [2 /*return*/, _a.sent()];
  1310. case 3:
  1311. e_1 = _a.sent();
  1312. if (!(e_1 instanceof util.FirebaseError && isUserInvalidated(e_1))) return [3 /*break*/, 5];
  1313. if (!(user.auth.currentUser === user)) return [3 /*break*/, 5];
  1314. return [4 /*yield*/, user.auth.signOut()];
  1315. case 4:
  1316. _a.sent();
  1317. _a.label = 5;
  1318. case 5: throw e_1;
  1319. case 6: return [2 /*return*/];
  1320. }
  1321. });
  1322. });
  1323. }
  1324. function isUserInvalidated(_a) {
  1325. var code = _a.code;
  1326. return (code === "auth/".concat("user-disabled" /* AuthErrorCode.USER_DISABLED */) ||
  1327. code === "auth/".concat("user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */));
  1328. }
  1329. /**
  1330. * @license
  1331. * Copyright 2020 Google LLC
  1332. *
  1333. * Licensed under the Apache License, Version 2.0 (the "License");
  1334. * you may not use this file except in compliance with the License.
  1335. * You may obtain a copy of the License at
  1336. *
  1337. * http://www.apache.org/licenses/LICENSE-2.0
  1338. *
  1339. * Unless required by applicable law or agreed to in writing, software
  1340. * distributed under the License is distributed on an "AS IS" BASIS,
  1341. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1342. * See the License for the specific language governing permissions and
  1343. * limitations under the License.
  1344. */
  1345. var ProactiveRefresh = /** @class */ (function () {
  1346. function ProactiveRefresh(user) {
  1347. this.user = user;
  1348. this.isRunning = false;
  1349. // Node timers and browser timers return fundamentally different types.
  1350. // We don't actually care what the value is but TS won't accept unknown and
  1351. // we can't cast properly in both environments.
  1352. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1353. this.timerId = null;
  1354. this.errorBackoff = 30000 /* Duration.RETRY_BACKOFF_MIN */;
  1355. }
  1356. ProactiveRefresh.prototype._start = function () {
  1357. if (this.isRunning) {
  1358. return;
  1359. }
  1360. this.isRunning = true;
  1361. this.schedule();
  1362. };
  1363. ProactiveRefresh.prototype._stop = function () {
  1364. if (!this.isRunning) {
  1365. return;
  1366. }
  1367. this.isRunning = false;
  1368. if (this.timerId !== null) {
  1369. clearTimeout(this.timerId);
  1370. }
  1371. };
  1372. ProactiveRefresh.prototype.getInterval = function (wasError) {
  1373. var _a;
  1374. if (wasError) {
  1375. var interval = this.errorBackoff;
  1376. this.errorBackoff = Math.min(this.errorBackoff * 2, 960000 /* Duration.RETRY_BACKOFF_MAX */);
  1377. return interval;
  1378. }
  1379. else {
  1380. // Reset the error backoff
  1381. this.errorBackoff = 30000 /* Duration.RETRY_BACKOFF_MIN */;
  1382. var expTime = (_a = this.user.stsTokenManager.expirationTime) !== null && _a !== void 0 ? _a : 0;
  1383. var interval = expTime - Date.now() - 300000 /* Duration.OFFSET */;
  1384. return Math.max(0, interval);
  1385. }
  1386. };
  1387. ProactiveRefresh.prototype.schedule = function (wasError) {
  1388. var _this = this;
  1389. if (wasError === void 0) { wasError = false; }
  1390. if (!this.isRunning) {
  1391. // Just in case...
  1392. return;
  1393. }
  1394. var interval = this.getInterval(wasError);
  1395. this.timerId = setTimeout(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  1396. return tslib.__generator(this, function (_a) {
  1397. switch (_a.label) {
  1398. case 0: return [4 /*yield*/, this.iteration()];
  1399. case 1:
  1400. _a.sent();
  1401. return [2 /*return*/];
  1402. }
  1403. });
  1404. }); }, interval);
  1405. };
  1406. ProactiveRefresh.prototype.iteration = function () {
  1407. return tslib.__awaiter(this, void 0, void 0, function () {
  1408. var e_1;
  1409. return tslib.__generator(this, function (_a) {
  1410. switch (_a.label) {
  1411. case 0:
  1412. _a.trys.push([0, 2, , 3]);
  1413. return [4 /*yield*/, this.user.getIdToken(true)];
  1414. case 1:
  1415. _a.sent();
  1416. return [3 /*break*/, 3];
  1417. case 2:
  1418. e_1 = _a.sent();
  1419. // Only retry on network errors
  1420. if ((e_1 === null || e_1 === void 0 ? void 0 : e_1.code) ===
  1421. "auth/".concat("network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */)) {
  1422. this.schedule(/* wasError */ true);
  1423. }
  1424. return [2 /*return*/];
  1425. case 3:
  1426. this.schedule();
  1427. return [2 /*return*/];
  1428. }
  1429. });
  1430. });
  1431. };
  1432. return ProactiveRefresh;
  1433. }());
  1434. /**
  1435. * @license
  1436. * Copyright 2020 Google LLC
  1437. *
  1438. * Licensed under the Apache License, Version 2.0 (the "License");
  1439. * you may not use this file except in compliance with the License.
  1440. * You may obtain a copy of the License at
  1441. *
  1442. * http://www.apache.org/licenses/LICENSE-2.0
  1443. *
  1444. * Unless required by applicable law or agreed to in writing, software
  1445. * distributed under the License is distributed on an "AS IS" BASIS,
  1446. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1447. * See the License for the specific language governing permissions and
  1448. * limitations under the License.
  1449. */
  1450. var UserMetadata = /** @class */ (function () {
  1451. function UserMetadata(createdAt, lastLoginAt) {
  1452. this.createdAt = createdAt;
  1453. this.lastLoginAt = lastLoginAt;
  1454. this._initializeTime();
  1455. }
  1456. UserMetadata.prototype._initializeTime = function () {
  1457. this.lastSignInTime = utcTimestampToDateString(this.lastLoginAt);
  1458. this.creationTime = utcTimestampToDateString(this.createdAt);
  1459. };
  1460. UserMetadata.prototype._copy = function (metadata) {
  1461. this.createdAt = metadata.createdAt;
  1462. this.lastLoginAt = metadata.lastLoginAt;
  1463. this._initializeTime();
  1464. };
  1465. UserMetadata.prototype.toJSON = function () {
  1466. return {
  1467. createdAt: this.createdAt,
  1468. lastLoginAt: this.lastLoginAt
  1469. };
  1470. };
  1471. return UserMetadata;
  1472. }());
  1473. /**
  1474. * @license
  1475. * Copyright 2019 Google LLC
  1476. *
  1477. * Licensed under the Apache License, Version 2.0 (the "License");
  1478. * you may not use this file except in compliance with the License.
  1479. * You may obtain a copy of the License at
  1480. *
  1481. * http://www.apache.org/licenses/LICENSE-2.0
  1482. *
  1483. * Unless required by applicable law or agreed to in writing, software
  1484. * distributed under the License is distributed on an "AS IS" BASIS,
  1485. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1486. * See the License for the specific language governing permissions and
  1487. * limitations under the License.
  1488. */
  1489. function _reloadWithoutSaving(user) {
  1490. var _a;
  1491. return tslib.__awaiter(this, void 0, void 0, function () {
  1492. var auth, idToken, response, coreAccount, newProviderData, providerData, oldIsAnonymous, newIsAnonymous, isAnonymous, updates;
  1493. return tslib.__generator(this, function (_b) {
  1494. switch (_b.label) {
  1495. case 0:
  1496. auth = user.auth;
  1497. return [4 /*yield*/, user.getIdToken()];
  1498. case 1:
  1499. idToken = _b.sent();
  1500. return [4 /*yield*/, _logoutIfInvalidated(user, getAccountInfo(auth, { idToken: idToken }))];
  1501. case 2:
  1502. response = _b.sent();
  1503. _assert(response === null || response === void 0 ? void 0 : response.users.length, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1504. coreAccount = response.users[0];
  1505. user._notifyReloadListener(coreAccount);
  1506. newProviderData = ((_a = coreAccount.providerUserInfo) === null || _a === void 0 ? void 0 : _a.length)
  1507. ? extractProviderData(coreAccount.providerUserInfo)
  1508. : [];
  1509. providerData = mergeProviderData(user.providerData, newProviderData);
  1510. oldIsAnonymous = user.isAnonymous;
  1511. newIsAnonymous = !(user.email && coreAccount.passwordHash) && !(providerData === null || providerData === void 0 ? void 0 : providerData.length);
  1512. isAnonymous = !oldIsAnonymous ? false : newIsAnonymous;
  1513. updates = {
  1514. uid: coreAccount.localId,
  1515. displayName: coreAccount.displayName || null,
  1516. photoURL: coreAccount.photoUrl || null,
  1517. email: coreAccount.email || null,
  1518. emailVerified: coreAccount.emailVerified || false,
  1519. phoneNumber: coreAccount.phoneNumber || null,
  1520. tenantId: coreAccount.tenantId || null,
  1521. providerData: providerData,
  1522. metadata: new UserMetadata(coreAccount.createdAt, coreAccount.lastLoginAt),
  1523. isAnonymous: isAnonymous
  1524. };
  1525. Object.assign(user, updates);
  1526. return [2 /*return*/];
  1527. }
  1528. });
  1529. });
  1530. }
  1531. /**
  1532. * Reloads user account data, if signed in.
  1533. *
  1534. * @param user - The user.
  1535. *
  1536. * @public
  1537. */
  1538. function reload(user) {
  1539. return tslib.__awaiter(this, void 0, void 0, function () {
  1540. var userInternal;
  1541. return tslib.__generator(this, function (_a) {
  1542. switch (_a.label) {
  1543. case 0:
  1544. userInternal = util.getModularInstance(user);
  1545. return [4 /*yield*/, _reloadWithoutSaving(userInternal)];
  1546. case 1:
  1547. _a.sent();
  1548. // Even though the current user hasn't changed, update
  1549. // current user will trigger a persistence update w/ the
  1550. // new info.
  1551. return [4 /*yield*/, userInternal.auth._persistUserIfCurrent(userInternal)];
  1552. case 2:
  1553. // Even though the current user hasn't changed, update
  1554. // current user will trigger a persistence update w/ the
  1555. // new info.
  1556. _a.sent();
  1557. userInternal.auth._notifyListenersIfCurrent(userInternal);
  1558. return [2 /*return*/];
  1559. }
  1560. });
  1561. });
  1562. }
  1563. function mergeProviderData(original, newData) {
  1564. var deduped = original.filter(function (o) { return !newData.some(function (n) { return n.providerId === o.providerId; }); });
  1565. return tslib.__spreadArray(tslib.__spreadArray([], deduped, true), newData, true);
  1566. }
  1567. function extractProviderData(providers) {
  1568. return providers.map(function (_a) {
  1569. var providerId = _a.providerId, provider = tslib.__rest(_a, ["providerId"]);
  1570. return {
  1571. providerId: providerId,
  1572. uid: provider.rawId || '',
  1573. displayName: provider.displayName || null,
  1574. email: provider.email || null,
  1575. phoneNumber: provider.phoneNumber || null,
  1576. photoURL: provider.photoUrl || null
  1577. };
  1578. });
  1579. }
  1580. /**
  1581. * @license
  1582. * Copyright 2020 Google LLC
  1583. *
  1584. * Licensed under the Apache License, Version 2.0 (the "License");
  1585. * you may not use this file except in compliance with the License.
  1586. * You may obtain a copy of the License at
  1587. *
  1588. * http://www.apache.org/licenses/LICENSE-2.0
  1589. *
  1590. * Unless required by applicable law or agreed to in writing, software
  1591. * distributed under the License is distributed on an "AS IS" BASIS,
  1592. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1593. * See the License for the specific language governing permissions and
  1594. * limitations under the License.
  1595. */
  1596. function requestStsToken(auth, refreshToken) {
  1597. return tslib.__awaiter(this, void 0, void 0, function () {
  1598. var response;
  1599. var _this = this;
  1600. return tslib.__generator(this, function (_a) {
  1601. switch (_a.label) {
  1602. case 0: return [4 /*yield*/, _performFetchWithErrorHandling(auth, {}, function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  1603. var body, _a, tokenApiHost, apiKey, url, headers;
  1604. return tslib.__generator(this, function (_b) {
  1605. switch (_b.label) {
  1606. case 0:
  1607. body = util.querystring({
  1608. 'grant_type': 'refresh_token',
  1609. 'refresh_token': refreshToken
  1610. }).slice(1);
  1611. _a = auth.config, tokenApiHost = _a.tokenApiHost, apiKey = _a.apiKey;
  1612. url = _getFinalTarget(auth, tokenApiHost, "/v1/token" /* Endpoint.TOKEN */, "key=".concat(apiKey));
  1613. return [4 /*yield*/, auth._getAdditionalHeaders()];
  1614. case 1:
  1615. headers = _b.sent();
  1616. headers["Content-Type" /* HttpHeader.CONTENT_TYPE */] = 'application/x-www-form-urlencoded';
  1617. return [2 /*return*/, FetchProvider.fetch()(url, {
  1618. method: "POST" /* HttpMethod.POST */,
  1619. headers: headers,
  1620. body: body
  1621. })];
  1622. }
  1623. });
  1624. }); })];
  1625. case 1:
  1626. response = _a.sent();
  1627. // The response comes back in snake_case. Convert to camel:
  1628. return [2 /*return*/, {
  1629. accessToken: response.access_token,
  1630. expiresIn: response.expires_in,
  1631. refreshToken: response.refresh_token
  1632. }];
  1633. }
  1634. });
  1635. });
  1636. }
  1637. /**
  1638. * @license
  1639. * Copyright 2020 Google LLC
  1640. *
  1641. * Licensed under the Apache License, Version 2.0 (the "License");
  1642. * you may not use this file except in compliance with the License.
  1643. * You may obtain a copy of the License at
  1644. *
  1645. * http://www.apache.org/licenses/LICENSE-2.0
  1646. *
  1647. * Unless required by applicable law or agreed to in writing, software
  1648. * distributed under the License is distributed on an "AS IS" BASIS,
  1649. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1650. * See the License for the specific language governing permissions and
  1651. * limitations under the License.
  1652. */
  1653. /**
  1654. * We need to mark this class as internal explicitly to exclude it in the public typings, because
  1655. * it references AuthInternal which has a circular dependency with UserInternal.
  1656. *
  1657. * @internal
  1658. */
  1659. var StsTokenManager = /** @class */ (function () {
  1660. function StsTokenManager() {
  1661. this.refreshToken = null;
  1662. this.accessToken = null;
  1663. this.expirationTime = null;
  1664. }
  1665. Object.defineProperty(StsTokenManager.prototype, "isExpired", {
  1666. get: function () {
  1667. return (!this.expirationTime ||
  1668. Date.now() > this.expirationTime - 30000 /* Buffer.TOKEN_REFRESH */);
  1669. },
  1670. enumerable: false,
  1671. configurable: true
  1672. });
  1673. StsTokenManager.prototype.updateFromServerResponse = function (response) {
  1674. _assert(response.idToken, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1675. _assert(typeof response.idToken !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1676. _assert(typeof response.refreshToken !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1677. var expiresIn = 'expiresIn' in response && typeof response.expiresIn !== 'undefined'
  1678. ? Number(response.expiresIn)
  1679. : _tokenExpiresIn(response.idToken);
  1680. this.updateTokensAndExpiration(response.idToken, response.refreshToken, expiresIn);
  1681. };
  1682. StsTokenManager.prototype.getToken = function (auth, forceRefresh) {
  1683. if (forceRefresh === void 0) { forceRefresh = false; }
  1684. return tslib.__awaiter(this, void 0, void 0, function () {
  1685. return tslib.__generator(this, function (_a) {
  1686. switch (_a.label) {
  1687. case 0:
  1688. _assert(!this.accessToken || this.refreshToken, auth, "user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */);
  1689. if (!forceRefresh && this.accessToken && !this.isExpired) {
  1690. return [2 /*return*/, this.accessToken];
  1691. }
  1692. if (!this.refreshToken) return [3 /*break*/, 2];
  1693. return [4 /*yield*/, this.refresh(auth, this.refreshToken)];
  1694. case 1:
  1695. _a.sent();
  1696. return [2 /*return*/, this.accessToken];
  1697. case 2: return [2 /*return*/, null];
  1698. }
  1699. });
  1700. });
  1701. };
  1702. StsTokenManager.prototype.clearRefreshToken = function () {
  1703. this.refreshToken = null;
  1704. };
  1705. StsTokenManager.prototype.refresh = function (auth, oldToken) {
  1706. return tslib.__awaiter(this, void 0, void 0, function () {
  1707. var _a, accessToken, refreshToken, expiresIn;
  1708. return tslib.__generator(this, function (_b) {
  1709. switch (_b.label) {
  1710. case 0: return [4 /*yield*/, requestStsToken(auth, oldToken)];
  1711. case 1:
  1712. _a = _b.sent(), accessToken = _a.accessToken, refreshToken = _a.refreshToken, expiresIn = _a.expiresIn;
  1713. this.updateTokensAndExpiration(accessToken, refreshToken, Number(expiresIn));
  1714. return [2 /*return*/];
  1715. }
  1716. });
  1717. });
  1718. };
  1719. StsTokenManager.prototype.updateTokensAndExpiration = function (accessToken, refreshToken, expiresInSec) {
  1720. this.refreshToken = refreshToken || null;
  1721. this.accessToken = accessToken || null;
  1722. this.expirationTime = Date.now() + expiresInSec * 1000;
  1723. };
  1724. StsTokenManager.fromJSON = function (appName, object) {
  1725. var refreshToken = object.refreshToken, accessToken = object.accessToken, expirationTime = object.expirationTime;
  1726. var manager = new StsTokenManager();
  1727. if (refreshToken) {
  1728. _assert(typeof refreshToken === 'string', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, {
  1729. appName: appName
  1730. });
  1731. manager.refreshToken = refreshToken;
  1732. }
  1733. if (accessToken) {
  1734. _assert(typeof accessToken === 'string', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, {
  1735. appName: appName
  1736. });
  1737. manager.accessToken = accessToken;
  1738. }
  1739. if (expirationTime) {
  1740. _assert(typeof expirationTime === 'number', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, {
  1741. appName: appName
  1742. });
  1743. manager.expirationTime = expirationTime;
  1744. }
  1745. return manager;
  1746. };
  1747. StsTokenManager.prototype.toJSON = function () {
  1748. return {
  1749. refreshToken: this.refreshToken,
  1750. accessToken: this.accessToken,
  1751. expirationTime: this.expirationTime
  1752. };
  1753. };
  1754. StsTokenManager.prototype._assign = function (stsTokenManager) {
  1755. this.accessToken = stsTokenManager.accessToken;
  1756. this.refreshToken = stsTokenManager.refreshToken;
  1757. this.expirationTime = stsTokenManager.expirationTime;
  1758. };
  1759. StsTokenManager.prototype._clone = function () {
  1760. return Object.assign(new StsTokenManager(), this.toJSON());
  1761. };
  1762. StsTokenManager.prototype._performRefresh = function () {
  1763. return debugFail('not implemented');
  1764. };
  1765. return StsTokenManager;
  1766. }());
  1767. /**
  1768. * @license
  1769. * Copyright 2020 Google LLC
  1770. *
  1771. * Licensed under the Apache License, Version 2.0 (the "License");
  1772. * you may not use this file except in compliance with the License.
  1773. * You may obtain a copy of the License at
  1774. *
  1775. * http://www.apache.org/licenses/LICENSE-2.0
  1776. *
  1777. * Unless required by applicable law or agreed to in writing, software
  1778. * distributed under the License is distributed on an "AS IS" BASIS,
  1779. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1780. * See the License for the specific language governing permissions and
  1781. * limitations under the License.
  1782. */
  1783. function assertStringOrUndefined(assertion, appName) {
  1784. _assert(typeof assertion === 'string' || typeof assertion === 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, { appName: appName });
  1785. }
  1786. var UserImpl = /** @class */ (function () {
  1787. function UserImpl(_a) {
  1788. var uid = _a.uid, auth = _a.auth, stsTokenManager = _a.stsTokenManager, opt = tslib.__rest(_a, ["uid", "auth", "stsTokenManager"]);
  1789. // For the user object, provider is always Firebase.
  1790. this.providerId = "firebase" /* ProviderId.FIREBASE */;
  1791. this.proactiveRefresh = new ProactiveRefresh(this);
  1792. this.reloadUserInfo = null;
  1793. this.reloadListener = null;
  1794. this.uid = uid;
  1795. this.auth = auth;
  1796. this.stsTokenManager = stsTokenManager;
  1797. this.accessToken = stsTokenManager.accessToken;
  1798. this.displayName = opt.displayName || null;
  1799. this.email = opt.email || null;
  1800. this.emailVerified = opt.emailVerified || false;
  1801. this.phoneNumber = opt.phoneNumber || null;
  1802. this.photoURL = opt.photoURL || null;
  1803. this.isAnonymous = opt.isAnonymous || false;
  1804. this.tenantId = opt.tenantId || null;
  1805. this.providerData = opt.providerData ? tslib.__spreadArray([], opt.providerData, true) : [];
  1806. this.metadata = new UserMetadata(opt.createdAt || undefined, opt.lastLoginAt || undefined);
  1807. }
  1808. UserImpl.prototype.getIdToken = function (forceRefresh) {
  1809. return tslib.__awaiter(this, void 0, void 0, function () {
  1810. var accessToken;
  1811. return tslib.__generator(this, function (_a) {
  1812. switch (_a.label) {
  1813. case 0: return [4 /*yield*/, _logoutIfInvalidated(this, this.stsTokenManager.getToken(this.auth, forceRefresh))];
  1814. case 1:
  1815. accessToken = _a.sent();
  1816. _assert(accessToken, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1817. if (!(this.accessToken !== accessToken)) return [3 /*break*/, 3];
  1818. this.accessToken = accessToken;
  1819. return [4 /*yield*/, this.auth._persistUserIfCurrent(this)];
  1820. case 2:
  1821. _a.sent();
  1822. this.auth._notifyListenersIfCurrent(this);
  1823. _a.label = 3;
  1824. case 3: return [2 /*return*/, accessToken];
  1825. }
  1826. });
  1827. });
  1828. };
  1829. UserImpl.prototype.getIdTokenResult = function (forceRefresh) {
  1830. return getIdTokenResult(this, forceRefresh);
  1831. };
  1832. UserImpl.prototype.reload = function () {
  1833. return reload(this);
  1834. };
  1835. UserImpl.prototype._assign = function (user) {
  1836. if (this === user) {
  1837. return;
  1838. }
  1839. _assert(this.uid === user.uid, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1840. this.displayName = user.displayName;
  1841. this.photoURL = user.photoURL;
  1842. this.email = user.email;
  1843. this.emailVerified = user.emailVerified;
  1844. this.phoneNumber = user.phoneNumber;
  1845. this.isAnonymous = user.isAnonymous;
  1846. this.tenantId = user.tenantId;
  1847. this.providerData = user.providerData.map(function (userInfo) { return (tslib.__assign({}, userInfo)); });
  1848. this.metadata._copy(user.metadata);
  1849. this.stsTokenManager._assign(user.stsTokenManager);
  1850. };
  1851. UserImpl.prototype._clone = function (auth) {
  1852. return new UserImpl(tslib.__assign(tslib.__assign({}, this), { auth: auth, stsTokenManager: this.stsTokenManager._clone() }));
  1853. };
  1854. UserImpl.prototype._onReload = function (callback) {
  1855. // There should only ever be one listener, and that is a single instance of MultiFactorUser
  1856. _assert(!this.reloadListener, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1857. this.reloadListener = callback;
  1858. if (this.reloadUserInfo) {
  1859. this._notifyReloadListener(this.reloadUserInfo);
  1860. this.reloadUserInfo = null;
  1861. }
  1862. };
  1863. UserImpl.prototype._notifyReloadListener = function (userInfo) {
  1864. if (this.reloadListener) {
  1865. this.reloadListener(userInfo);
  1866. }
  1867. else {
  1868. // If no listener is subscribed yet, save the result so it's available when they do subscribe
  1869. this.reloadUserInfo = userInfo;
  1870. }
  1871. };
  1872. UserImpl.prototype._startProactiveRefresh = function () {
  1873. this.proactiveRefresh._start();
  1874. };
  1875. UserImpl.prototype._stopProactiveRefresh = function () {
  1876. this.proactiveRefresh._stop();
  1877. };
  1878. UserImpl.prototype._updateTokensIfNecessary = function (response, reload) {
  1879. if (reload === void 0) { reload = false; }
  1880. return tslib.__awaiter(this, void 0, void 0, function () {
  1881. var tokensRefreshed;
  1882. return tslib.__generator(this, function (_a) {
  1883. switch (_a.label) {
  1884. case 0:
  1885. tokensRefreshed = false;
  1886. if (response.idToken &&
  1887. response.idToken !== this.stsTokenManager.accessToken) {
  1888. this.stsTokenManager.updateFromServerResponse(response);
  1889. tokensRefreshed = true;
  1890. }
  1891. if (!reload) return [3 /*break*/, 2];
  1892. return [4 /*yield*/, _reloadWithoutSaving(this)];
  1893. case 1:
  1894. _a.sent();
  1895. _a.label = 2;
  1896. case 2: return [4 /*yield*/, this.auth._persistUserIfCurrent(this)];
  1897. case 3:
  1898. _a.sent();
  1899. if (tokensRefreshed) {
  1900. this.auth._notifyListenersIfCurrent(this);
  1901. }
  1902. return [2 /*return*/];
  1903. }
  1904. });
  1905. });
  1906. };
  1907. UserImpl.prototype.delete = function () {
  1908. return tslib.__awaiter(this, void 0, void 0, function () {
  1909. var idToken;
  1910. return tslib.__generator(this, function (_a) {
  1911. switch (_a.label) {
  1912. case 0: return [4 /*yield*/, this.getIdToken()];
  1913. case 1:
  1914. idToken = _a.sent();
  1915. return [4 /*yield*/, _logoutIfInvalidated(this, deleteAccount(this.auth, { idToken: idToken }))];
  1916. case 2:
  1917. _a.sent();
  1918. this.stsTokenManager.clearRefreshToken();
  1919. // TODO: Determine if cancellable-promises are necessary to use in this class so that delete()
  1920. // cancels pending actions...
  1921. return [2 /*return*/, this.auth.signOut()];
  1922. }
  1923. });
  1924. });
  1925. };
  1926. UserImpl.prototype.toJSON = function () {
  1927. return tslib.__assign(tslib.__assign({ uid: this.uid, email: this.email || undefined, emailVerified: this.emailVerified, displayName: this.displayName || undefined, isAnonymous: this.isAnonymous, photoURL: this.photoURL || undefined, phoneNumber: this.phoneNumber || undefined, tenantId: this.tenantId || undefined, providerData: this.providerData.map(function (userInfo) { return (tslib.__assign({}, userInfo)); }), stsTokenManager: this.stsTokenManager.toJSON(),
  1928. // Redirect event ID must be maintained in case there is a pending
  1929. // redirect event.
  1930. _redirectEventId: this._redirectEventId }, this.metadata.toJSON()), {
  1931. // Required for compatibility with the legacy SDK (go/firebase-auth-sdk-persistence-parsing):
  1932. apiKey: this.auth.config.apiKey, appName: this.auth.name });
  1933. };
  1934. Object.defineProperty(UserImpl.prototype, "refreshToken", {
  1935. get: function () {
  1936. return this.stsTokenManager.refreshToken || '';
  1937. },
  1938. enumerable: false,
  1939. configurable: true
  1940. });
  1941. UserImpl._fromJSON = function (auth, object) {
  1942. var _a, _b, _c, _d, _e, _f, _g, _h;
  1943. var displayName = (_a = object.displayName) !== null && _a !== void 0 ? _a : undefined;
  1944. var email = (_b = object.email) !== null && _b !== void 0 ? _b : undefined;
  1945. var phoneNumber = (_c = object.phoneNumber) !== null && _c !== void 0 ? _c : undefined;
  1946. var photoURL = (_d = object.photoURL) !== null && _d !== void 0 ? _d : undefined;
  1947. var tenantId = (_e = object.tenantId) !== null && _e !== void 0 ? _e : undefined;
  1948. var _redirectEventId = (_f = object._redirectEventId) !== null && _f !== void 0 ? _f : undefined;
  1949. var createdAt = (_g = object.createdAt) !== null && _g !== void 0 ? _g : undefined;
  1950. var lastLoginAt = (_h = object.lastLoginAt) !== null && _h !== void 0 ? _h : undefined;
  1951. var uid = object.uid, emailVerified = object.emailVerified, isAnonymous = object.isAnonymous, providerData = object.providerData, plainObjectTokenManager = object.stsTokenManager;
  1952. _assert(uid && plainObjectTokenManager, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1953. var stsTokenManager = StsTokenManager.fromJSON(this.name, plainObjectTokenManager);
  1954. _assert(typeof uid === 'string', auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1955. assertStringOrUndefined(displayName, auth.name);
  1956. assertStringOrUndefined(email, auth.name);
  1957. _assert(typeof emailVerified === 'boolean', auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1958. _assert(typeof isAnonymous === 'boolean', auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  1959. assertStringOrUndefined(phoneNumber, auth.name);
  1960. assertStringOrUndefined(photoURL, auth.name);
  1961. assertStringOrUndefined(tenantId, auth.name);
  1962. assertStringOrUndefined(_redirectEventId, auth.name);
  1963. assertStringOrUndefined(createdAt, auth.name);
  1964. assertStringOrUndefined(lastLoginAt, auth.name);
  1965. var user = new UserImpl({
  1966. uid: uid,
  1967. auth: auth,
  1968. email: email,
  1969. emailVerified: emailVerified,
  1970. displayName: displayName,
  1971. isAnonymous: isAnonymous,
  1972. photoURL: photoURL,
  1973. phoneNumber: phoneNumber,
  1974. tenantId: tenantId,
  1975. stsTokenManager: stsTokenManager,
  1976. createdAt: createdAt,
  1977. lastLoginAt: lastLoginAt
  1978. });
  1979. if (providerData && Array.isArray(providerData)) {
  1980. user.providerData = providerData.map(function (userInfo) { return (tslib.__assign({}, userInfo)); });
  1981. }
  1982. if (_redirectEventId) {
  1983. user._redirectEventId = _redirectEventId;
  1984. }
  1985. return user;
  1986. };
  1987. /**
  1988. * Initialize a User from an idToken server response
  1989. * @param auth
  1990. * @param idTokenResponse
  1991. */
  1992. UserImpl._fromIdTokenResponse = function (auth, idTokenResponse, isAnonymous) {
  1993. if (isAnonymous === void 0) { isAnonymous = false; }
  1994. return tslib.__awaiter(this, void 0, void 0, function () {
  1995. var stsTokenManager, user;
  1996. return tslib.__generator(this, function (_a) {
  1997. switch (_a.label) {
  1998. case 0:
  1999. stsTokenManager = new StsTokenManager();
  2000. stsTokenManager.updateFromServerResponse(idTokenResponse);
  2001. user = new UserImpl({
  2002. uid: idTokenResponse.localId,
  2003. auth: auth,
  2004. stsTokenManager: stsTokenManager,
  2005. isAnonymous: isAnonymous
  2006. });
  2007. // Updates the user info and data and resolves with a user instance.
  2008. return [4 /*yield*/, _reloadWithoutSaving(user)];
  2009. case 1:
  2010. // Updates the user info and data and resolves with a user instance.
  2011. _a.sent();
  2012. return [2 /*return*/, user];
  2013. }
  2014. });
  2015. });
  2016. };
  2017. return UserImpl;
  2018. }());
  2019. /**
  2020. * @license
  2021. * Copyright 2019 Google LLC
  2022. *
  2023. * Licensed under the Apache License, Version 2.0 (the "License");
  2024. * you may not use this file except in compliance with the License.
  2025. * You may obtain a copy of the License at
  2026. *
  2027. * http://www.apache.org/licenses/LICENSE-2.0
  2028. *
  2029. * Unless required by applicable law or agreed to in writing, software
  2030. * distributed under the License is distributed on an "AS IS" BASIS,
  2031. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2032. * See the License for the specific language governing permissions and
  2033. * limitations under the License.
  2034. */
  2035. var InMemoryPersistence = /** @class */ (function () {
  2036. function InMemoryPersistence() {
  2037. this.type = "NONE" /* PersistenceType.NONE */;
  2038. this.storage = {};
  2039. }
  2040. InMemoryPersistence.prototype._isAvailable = function () {
  2041. return tslib.__awaiter(this, void 0, void 0, function () {
  2042. return tslib.__generator(this, function (_a) {
  2043. return [2 /*return*/, true];
  2044. });
  2045. });
  2046. };
  2047. InMemoryPersistence.prototype._set = function (key, value) {
  2048. return tslib.__awaiter(this, void 0, void 0, function () {
  2049. return tslib.__generator(this, function (_a) {
  2050. this.storage[key] = value;
  2051. return [2 /*return*/];
  2052. });
  2053. });
  2054. };
  2055. InMemoryPersistence.prototype._get = function (key) {
  2056. return tslib.__awaiter(this, void 0, void 0, function () {
  2057. var value;
  2058. return tslib.__generator(this, function (_a) {
  2059. value = this.storage[key];
  2060. return [2 /*return*/, value === undefined ? null : value];
  2061. });
  2062. });
  2063. };
  2064. InMemoryPersistence.prototype._remove = function (key) {
  2065. return tslib.__awaiter(this, void 0, void 0, function () {
  2066. return tslib.__generator(this, function (_a) {
  2067. delete this.storage[key];
  2068. return [2 /*return*/];
  2069. });
  2070. });
  2071. };
  2072. InMemoryPersistence.prototype._addListener = function (_key, _listener) {
  2073. // Listeners are not supported for in-memory storage since it cannot be shared across windows/workers
  2074. return;
  2075. };
  2076. InMemoryPersistence.prototype._removeListener = function (_key, _listener) {
  2077. // Listeners are not supported for in-memory storage since it cannot be shared across windows/workers
  2078. return;
  2079. };
  2080. InMemoryPersistence.type = 'NONE';
  2081. return InMemoryPersistence;
  2082. }());
  2083. /**
  2084. * An implementation of {@link Persistence} of type 'NONE'.
  2085. *
  2086. * @public
  2087. */
  2088. var inMemoryPersistence = InMemoryPersistence;
  2089. /**
  2090. * @license
  2091. * Copyright 2019 Google LLC
  2092. *
  2093. * Licensed under the Apache License, Version 2.0 (the "License");
  2094. * you may not use this file except in compliance with the License.
  2095. * You may obtain a copy of the License at
  2096. *
  2097. * http://www.apache.org/licenses/LICENSE-2.0
  2098. *
  2099. * Unless required by applicable law or agreed to in writing, software
  2100. * distributed under the License is distributed on an "AS IS" BASIS,
  2101. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2102. * See the License for the specific language governing permissions and
  2103. * limitations under the License.
  2104. */
  2105. function _persistenceKeyName(key, apiKey, appName) {
  2106. return "".concat("firebase" /* Namespace.PERSISTENCE */, ":").concat(key, ":").concat(apiKey, ":").concat(appName);
  2107. }
  2108. var PersistenceUserManager = /** @class */ (function () {
  2109. function PersistenceUserManager(persistence, auth, userKey) {
  2110. this.persistence = persistence;
  2111. this.auth = auth;
  2112. this.userKey = userKey;
  2113. var _a = this.auth, config = _a.config, name = _a.name;
  2114. this.fullUserKey = _persistenceKeyName(this.userKey, config.apiKey, name);
  2115. this.fullPersistenceKey = _persistenceKeyName("persistence" /* KeyName.PERSISTENCE_USER */, config.apiKey, name);
  2116. this.boundEventHandler = auth._onStorageEvent.bind(auth);
  2117. this.persistence._addListener(this.fullUserKey, this.boundEventHandler);
  2118. }
  2119. PersistenceUserManager.prototype.setCurrentUser = function (user) {
  2120. return this.persistence._set(this.fullUserKey, user.toJSON());
  2121. };
  2122. PersistenceUserManager.prototype.getCurrentUser = function () {
  2123. return tslib.__awaiter(this, void 0, void 0, function () {
  2124. var blob;
  2125. return tslib.__generator(this, function (_a) {
  2126. switch (_a.label) {
  2127. case 0: return [4 /*yield*/, this.persistence._get(this.fullUserKey)];
  2128. case 1:
  2129. blob = _a.sent();
  2130. return [2 /*return*/, blob ? UserImpl._fromJSON(this.auth, blob) : null];
  2131. }
  2132. });
  2133. });
  2134. };
  2135. PersistenceUserManager.prototype.removeCurrentUser = function () {
  2136. return this.persistence._remove(this.fullUserKey);
  2137. };
  2138. PersistenceUserManager.prototype.savePersistenceForRedirect = function () {
  2139. return this.persistence._set(this.fullPersistenceKey, this.persistence.type);
  2140. };
  2141. PersistenceUserManager.prototype.setPersistence = function (newPersistence) {
  2142. return tslib.__awaiter(this, void 0, void 0, function () {
  2143. var currentUser;
  2144. return tslib.__generator(this, function (_a) {
  2145. switch (_a.label) {
  2146. case 0:
  2147. if (this.persistence === newPersistence) {
  2148. return [2 /*return*/];
  2149. }
  2150. return [4 /*yield*/, this.getCurrentUser()];
  2151. case 1:
  2152. currentUser = _a.sent();
  2153. return [4 /*yield*/, this.removeCurrentUser()];
  2154. case 2:
  2155. _a.sent();
  2156. this.persistence = newPersistence;
  2157. if (currentUser) {
  2158. return [2 /*return*/, this.setCurrentUser(currentUser)];
  2159. }
  2160. return [2 /*return*/];
  2161. }
  2162. });
  2163. });
  2164. };
  2165. PersistenceUserManager.prototype.delete = function () {
  2166. this.persistence._removeListener(this.fullUserKey, this.boundEventHandler);
  2167. };
  2168. PersistenceUserManager.create = function (auth, persistenceHierarchy, userKey) {
  2169. if (userKey === void 0) { userKey = "authUser" /* KeyName.AUTH_USER */; }
  2170. return tslib.__awaiter(this, void 0, void 0, function () {
  2171. var availablePersistences, selectedPersistence, key, userToMigrate, _i, persistenceHierarchy_1, persistence, blob, user, migrationHierarchy;
  2172. var _this = this;
  2173. return tslib.__generator(this, function (_b) {
  2174. switch (_b.label) {
  2175. case 0:
  2176. if (!persistenceHierarchy.length) {
  2177. return [2 /*return*/, new PersistenceUserManager(_getInstance(inMemoryPersistence), auth, userKey)];
  2178. }
  2179. return [4 /*yield*/, Promise.all(persistenceHierarchy.map(function (persistence) { return tslib.__awaiter(_this, void 0, void 0, function () {
  2180. return tslib.__generator(this, function (_a) {
  2181. switch (_a.label) {
  2182. case 0: return [4 /*yield*/, persistence._isAvailable()];
  2183. case 1:
  2184. if (_a.sent()) {
  2185. return [2 /*return*/, persistence];
  2186. }
  2187. return [2 /*return*/, undefined];
  2188. }
  2189. });
  2190. }); }))];
  2191. case 1:
  2192. availablePersistences = (_b.sent()).filter(function (persistence) { return persistence; });
  2193. selectedPersistence = availablePersistences[0] ||
  2194. _getInstance(inMemoryPersistence);
  2195. key = _persistenceKeyName(userKey, auth.config.apiKey, auth.name);
  2196. userToMigrate = null;
  2197. _i = 0, persistenceHierarchy_1 = persistenceHierarchy;
  2198. _b.label = 2;
  2199. case 2:
  2200. if (!(_i < persistenceHierarchy_1.length)) return [3 /*break*/, 7];
  2201. persistence = persistenceHierarchy_1[_i];
  2202. _b.label = 3;
  2203. case 3:
  2204. _b.trys.push([3, 5, , 6]);
  2205. return [4 /*yield*/, persistence._get(key)];
  2206. case 4:
  2207. blob = _b.sent();
  2208. if (blob) {
  2209. user = UserImpl._fromJSON(auth, blob);
  2210. if (persistence !== selectedPersistence) {
  2211. userToMigrate = user;
  2212. }
  2213. selectedPersistence = persistence;
  2214. return [3 /*break*/, 7];
  2215. }
  2216. return [3 /*break*/, 6];
  2217. case 5:
  2218. _b.sent();
  2219. return [3 /*break*/, 6];
  2220. case 6:
  2221. _i++;
  2222. return [3 /*break*/, 2];
  2223. case 7:
  2224. migrationHierarchy = availablePersistences.filter(function (p) { return p._shouldAllowMigration; });
  2225. // If the persistence does _not_ allow migration, just finish off here
  2226. if (!selectedPersistence._shouldAllowMigration ||
  2227. !migrationHierarchy.length) {
  2228. return [2 /*return*/, new PersistenceUserManager(selectedPersistence, auth, userKey)];
  2229. }
  2230. selectedPersistence = migrationHierarchy[0];
  2231. if (!userToMigrate) return [3 /*break*/, 9];
  2232. // This normally shouldn't throw since chosenPersistence.isAvailable() is true, but if it does
  2233. // we'll just let it bubble to surface the error.
  2234. return [4 /*yield*/, selectedPersistence._set(key, userToMigrate.toJSON())];
  2235. case 8:
  2236. // This normally shouldn't throw since chosenPersistence.isAvailable() is true, but if it does
  2237. // we'll just let it bubble to surface the error.
  2238. _b.sent();
  2239. _b.label = 9;
  2240. case 9:
  2241. // Attempt to clear the key in other persistences but ignore errors. This helps prevent issues
  2242. // such as users getting stuck with a previous account after signing out and refreshing the tab.
  2243. return [4 /*yield*/, Promise.all(persistenceHierarchy.map(function (persistence) { return tslib.__awaiter(_this, void 0, void 0, function () {
  2244. return tslib.__generator(this, function (_b) {
  2245. switch (_b.label) {
  2246. case 0:
  2247. if (!(persistence !== selectedPersistence)) return [3 /*break*/, 4];
  2248. _b.label = 1;
  2249. case 1:
  2250. _b.trys.push([1, 3, , 4]);
  2251. return [4 /*yield*/, persistence._remove(key)];
  2252. case 2:
  2253. _b.sent();
  2254. return [3 /*break*/, 4];
  2255. case 3:
  2256. _b.sent();
  2257. return [3 /*break*/, 4];
  2258. case 4: return [2 /*return*/];
  2259. }
  2260. });
  2261. }); }))];
  2262. case 10:
  2263. // Attempt to clear the key in other persistences but ignore errors. This helps prevent issues
  2264. // such as users getting stuck with a previous account after signing out and refreshing the tab.
  2265. _b.sent();
  2266. return [2 /*return*/, new PersistenceUserManager(selectedPersistence, auth, userKey)];
  2267. }
  2268. });
  2269. });
  2270. };
  2271. return PersistenceUserManager;
  2272. }());
  2273. /**
  2274. * @license
  2275. * Copyright 2020 Google LLC
  2276. *
  2277. * Licensed under the Apache License, Version 2.0 (the "License");
  2278. * you may not use this file except in compliance with the License.
  2279. * You may obtain a copy of the License at
  2280. *
  2281. * http://www.apache.org/licenses/LICENSE-2.0
  2282. *
  2283. * Unless required by applicable law or agreed to in writing, software
  2284. * distributed under the License is distributed on an "AS IS" BASIS,
  2285. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2286. * See the License for the specific language governing permissions and
  2287. * limitations under the License.
  2288. */
  2289. /**
  2290. * Determine the browser for the purposes of reporting usage to the API
  2291. */
  2292. function _getBrowserName(userAgent) {
  2293. var ua = userAgent.toLowerCase();
  2294. if (ua.includes('opera/') || ua.includes('opr/') || ua.includes('opios/')) {
  2295. return "Opera" /* BrowserName.OPERA */;
  2296. }
  2297. else if (_isIEMobile(ua)) {
  2298. // Windows phone IEMobile browser.
  2299. return "IEMobile" /* BrowserName.IEMOBILE */;
  2300. }
  2301. else if (ua.includes('msie') || ua.includes('trident/')) {
  2302. return "IE" /* BrowserName.IE */;
  2303. }
  2304. else if (ua.includes('edge/')) {
  2305. return "Edge" /* BrowserName.EDGE */;
  2306. }
  2307. else if (_isFirefox(ua)) {
  2308. return "Firefox" /* BrowserName.FIREFOX */;
  2309. }
  2310. else if (ua.includes('silk/')) {
  2311. return "Silk" /* BrowserName.SILK */;
  2312. }
  2313. else if (_isBlackBerry(ua)) {
  2314. // Blackberry browser.
  2315. return "Blackberry" /* BrowserName.BLACKBERRY */;
  2316. }
  2317. else if (_isWebOS(ua)) {
  2318. // WebOS default browser.
  2319. return "Webos" /* BrowserName.WEBOS */;
  2320. }
  2321. else if (_isSafari(ua)) {
  2322. return "Safari" /* BrowserName.SAFARI */;
  2323. }
  2324. else if ((ua.includes('chrome/') || _isChromeIOS(ua)) &&
  2325. !ua.includes('edge/')) {
  2326. return "Chrome" /* BrowserName.CHROME */;
  2327. }
  2328. else if (_isAndroid(ua)) {
  2329. // Android stock browser.
  2330. return "Android" /* BrowserName.ANDROID */;
  2331. }
  2332. else {
  2333. // Most modern browsers have name/version at end of user agent string.
  2334. var re = /([a-zA-Z\d\.]+)\/[a-zA-Z\d\.]*$/;
  2335. var matches = userAgent.match(re);
  2336. if ((matches === null || matches === void 0 ? void 0 : matches.length) === 2) {
  2337. return matches[1];
  2338. }
  2339. }
  2340. return "Other" /* BrowserName.OTHER */;
  2341. }
  2342. function _isFirefox(ua) {
  2343. if (ua === void 0) { ua = util.getUA(); }
  2344. return /firefox\//i.test(ua);
  2345. }
  2346. function _isSafari(userAgent) {
  2347. if (userAgent === void 0) { userAgent = util.getUA(); }
  2348. var ua = userAgent.toLowerCase();
  2349. return (ua.includes('safari/') &&
  2350. !ua.includes('chrome/') &&
  2351. !ua.includes('crios/') &&
  2352. !ua.includes('android'));
  2353. }
  2354. function _isChromeIOS(ua) {
  2355. if (ua === void 0) { ua = util.getUA(); }
  2356. return /crios\//i.test(ua);
  2357. }
  2358. function _isIEMobile(ua) {
  2359. if (ua === void 0) { ua = util.getUA(); }
  2360. return /iemobile/i.test(ua);
  2361. }
  2362. function _isAndroid(ua) {
  2363. if (ua === void 0) { ua = util.getUA(); }
  2364. return /android/i.test(ua);
  2365. }
  2366. function _isBlackBerry(ua) {
  2367. if (ua === void 0) { ua = util.getUA(); }
  2368. return /blackberry/i.test(ua);
  2369. }
  2370. function _isWebOS(ua) {
  2371. if (ua === void 0) { ua = util.getUA(); }
  2372. return /webos/i.test(ua);
  2373. }
  2374. function _isIOS(ua) {
  2375. if (ua === void 0) { ua = util.getUA(); }
  2376. return (/iphone|ipad|ipod/i.test(ua) ||
  2377. (/macintosh/i.test(ua) && /mobile/i.test(ua)));
  2378. }
  2379. function _isIOS7Or8(ua) {
  2380. if (ua === void 0) { ua = util.getUA(); }
  2381. return (/(iPad|iPhone|iPod).*OS 7_\d/i.test(ua) ||
  2382. /(iPad|iPhone|iPod).*OS 8_\d/i.test(ua));
  2383. }
  2384. function _isIE10() {
  2385. return util.isIE() && document.documentMode === 10;
  2386. }
  2387. function _isMobileBrowser(ua) {
  2388. if (ua === void 0) { ua = util.getUA(); }
  2389. // TODO: implement getBrowserName equivalent for OS.
  2390. return (_isIOS(ua) ||
  2391. _isAndroid(ua) ||
  2392. _isWebOS(ua) ||
  2393. _isBlackBerry(ua) ||
  2394. /windows phone/i.test(ua) ||
  2395. _isIEMobile(ua));
  2396. }
  2397. function _isIframe() {
  2398. try {
  2399. // Check that the current window is not the top window.
  2400. // If so, return true.
  2401. return !!(window && window !== window.top);
  2402. }
  2403. catch (e) {
  2404. return false;
  2405. }
  2406. }
  2407. /**
  2408. * @license
  2409. * Copyright 2020 Google LLC
  2410. *
  2411. * Licensed under the Apache License, Version 2.0 (the "License");
  2412. * you may not use this file except in compliance with the License.
  2413. * You may obtain a copy of the License at
  2414. *
  2415. * http://www.apache.org/licenses/LICENSE-2.0
  2416. *
  2417. * Unless required by applicable law or agreed to in writing, software
  2418. * distributed under the License is distributed on an "AS IS" BASIS,
  2419. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2420. * See the License for the specific language governing permissions and
  2421. * limitations under the License.
  2422. */
  2423. /*
  2424. * Determine the SDK version string
  2425. */
  2426. function _getClientVersion(clientPlatform, frameworks) {
  2427. if (frameworks === void 0) { frameworks = []; }
  2428. var reportedPlatform;
  2429. switch (clientPlatform) {
  2430. case "Browser" /* ClientPlatform.BROWSER */:
  2431. // In a browser environment, report the browser name.
  2432. reportedPlatform = _getBrowserName(util.getUA());
  2433. break;
  2434. case "Worker" /* ClientPlatform.WORKER */:
  2435. // Technically a worker runs from a browser but we need to differentiate a
  2436. // worker from a browser.
  2437. // For example: Chrome-Worker/JsCore/4.9.1/FirebaseCore-web.
  2438. reportedPlatform = "".concat(_getBrowserName(util.getUA()), "-").concat(clientPlatform);
  2439. break;
  2440. default:
  2441. reportedPlatform = clientPlatform;
  2442. }
  2443. var reportedFrameworks = frameworks.length
  2444. ? frameworks.join(',')
  2445. : 'FirebaseCore-web'; /* default value if no other framework is used */
  2446. return "".concat(reportedPlatform, "/").concat("JsCore" /* ClientImplementation.CORE */, "/").concat(app.SDK_VERSION, "/").concat(reportedFrameworks);
  2447. }
  2448. /**
  2449. * @license
  2450. * Copyright 2022 Google LLC
  2451. *
  2452. * Licensed under the Apache License, Version 2.0 (the "License");
  2453. * you may not use this file except in compliance with the License.
  2454. * You may obtain a copy of the License at
  2455. *
  2456. * http://www.apache.org/licenses/LICENSE-2.0
  2457. *
  2458. * Unless required by applicable law or agreed to in writing, software
  2459. * distributed under the License is distributed on an "AS IS" BASIS,
  2460. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2461. * See the License for the specific language governing permissions and
  2462. * limitations under the License.
  2463. */
  2464. var AuthMiddlewareQueue = /** @class */ (function () {
  2465. function AuthMiddlewareQueue(auth) {
  2466. this.auth = auth;
  2467. this.queue = [];
  2468. }
  2469. AuthMiddlewareQueue.prototype.pushCallback = function (callback, onAbort) {
  2470. var _this = this;
  2471. // The callback could be sync or async. Wrap it into a
  2472. // function that is always async.
  2473. var wrappedCallback = function (user) {
  2474. return new Promise(function (resolve, reject) {
  2475. try {
  2476. var result = callback(user);
  2477. // Either resolve with existing promise or wrap a non-promise
  2478. // return value into a promise.
  2479. resolve(result);
  2480. }
  2481. catch (e) {
  2482. // Sync callback throws.
  2483. reject(e);
  2484. }
  2485. });
  2486. };
  2487. // Attach the onAbort if present
  2488. wrappedCallback.onAbort = onAbort;
  2489. this.queue.push(wrappedCallback);
  2490. var index = this.queue.length - 1;
  2491. return function () {
  2492. // Unsubscribe. Replace with no-op. Do not remove from array, or it will disturb
  2493. // indexing of other elements.
  2494. _this.queue[index] = function () { return Promise.resolve(); };
  2495. };
  2496. };
  2497. AuthMiddlewareQueue.prototype.runMiddleware = function (nextUser) {
  2498. return tslib.__awaiter(this, void 0, void 0, function () {
  2499. var onAbortStack, _i, _a, beforeStateCallback, e_1, _b, onAbortStack_1, onAbort;
  2500. return tslib.__generator(this, function (_c) {
  2501. switch (_c.label) {
  2502. case 0:
  2503. if (this.auth.currentUser === nextUser) {
  2504. return [2 /*return*/];
  2505. }
  2506. onAbortStack = [];
  2507. _c.label = 1;
  2508. case 1:
  2509. _c.trys.push([1, 6, , 7]);
  2510. _i = 0, _a = this.queue;
  2511. _c.label = 2;
  2512. case 2:
  2513. if (!(_i < _a.length)) return [3 /*break*/, 5];
  2514. beforeStateCallback = _a[_i];
  2515. return [4 /*yield*/, beforeStateCallback(nextUser)];
  2516. case 3:
  2517. _c.sent();
  2518. // Only push the onAbort if the callback succeeds
  2519. if (beforeStateCallback.onAbort) {
  2520. onAbortStack.push(beforeStateCallback.onAbort);
  2521. }
  2522. _c.label = 4;
  2523. case 4:
  2524. _i++;
  2525. return [3 /*break*/, 2];
  2526. case 5: return [3 /*break*/, 7];
  2527. case 6:
  2528. e_1 = _c.sent();
  2529. // Run all onAbort, with separate try/catch to ignore any errors and
  2530. // continue
  2531. onAbortStack.reverse();
  2532. for (_b = 0, onAbortStack_1 = onAbortStack; _b < onAbortStack_1.length; _b++) {
  2533. onAbort = onAbortStack_1[_b];
  2534. try {
  2535. onAbort();
  2536. }
  2537. catch (_) {
  2538. /* swallow error */
  2539. }
  2540. }
  2541. throw this.auth._errorFactory.create("login-blocked" /* AuthErrorCode.LOGIN_BLOCKED */, {
  2542. originalMessage: e_1 === null || e_1 === void 0 ? void 0 : e_1.message
  2543. });
  2544. case 7: return [2 /*return*/];
  2545. }
  2546. });
  2547. });
  2548. };
  2549. return AuthMiddlewareQueue;
  2550. }());
  2551. /**
  2552. * @license
  2553. * Copyright 2020 Google LLC
  2554. *
  2555. * Licensed under the Apache License, Version 2.0 (the "License");
  2556. * you may not use this file except in compliance with the License.
  2557. * You may obtain a copy of the License at
  2558. *
  2559. * http://www.apache.org/licenses/LICENSE-2.0
  2560. *
  2561. * Unless required by applicable law or agreed to in writing, software
  2562. * distributed under the License is distributed on an "AS IS" BASIS,
  2563. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2564. * See the License for the specific language governing permissions and
  2565. * limitations under the License.
  2566. */
  2567. var AuthImpl = /** @class */ (function () {
  2568. function AuthImpl(app, heartbeatServiceProvider, config) {
  2569. this.app = app;
  2570. this.heartbeatServiceProvider = heartbeatServiceProvider;
  2571. this.config = config;
  2572. this.currentUser = null;
  2573. this.emulatorConfig = null;
  2574. this.operations = Promise.resolve();
  2575. this.authStateSubscription = new Subscription(this);
  2576. this.idTokenSubscription = new Subscription(this);
  2577. this.beforeStateQueue = new AuthMiddlewareQueue(this);
  2578. this.redirectUser = null;
  2579. this.isProactiveRefreshEnabled = false;
  2580. // Any network calls will set this to true and prevent subsequent emulator
  2581. // initialization
  2582. this._canInitEmulator = true;
  2583. this._isInitialized = false;
  2584. this._deleted = false;
  2585. this._initializationPromise = null;
  2586. this._popupRedirectResolver = null;
  2587. this._errorFactory = _DEFAULT_AUTH_ERROR_FACTORY;
  2588. // Tracks the last notified UID for state change listeners to prevent
  2589. // repeated calls to the callbacks. Undefined means it's never been
  2590. // called, whereas null means it's been called with a signed out user
  2591. this.lastNotifiedUid = undefined;
  2592. this.languageCode = null;
  2593. this.tenantId = null;
  2594. this.settings = { appVerificationDisabledForTesting: false };
  2595. this.frameworks = [];
  2596. this.name = app.name;
  2597. this.clientVersion = config.sdkClientVersion;
  2598. }
  2599. AuthImpl.prototype._initializeWithPersistence = function (persistenceHierarchy, popupRedirectResolver) {
  2600. var _this = this;
  2601. if (popupRedirectResolver) {
  2602. this._popupRedirectResolver = _getInstance(popupRedirectResolver);
  2603. }
  2604. // Have to check for app deletion throughout initialization (after each
  2605. // promise resolution)
  2606. this._initializationPromise = this.queue(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  2607. var _a;
  2608. var _b, _c;
  2609. return tslib.__generator(this, function (_d) {
  2610. switch (_d.label) {
  2611. case 0:
  2612. if (this._deleted) {
  2613. return [2 /*return*/];
  2614. }
  2615. _a = this;
  2616. return [4 /*yield*/, PersistenceUserManager.create(this, persistenceHierarchy)];
  2617. case 1:
  2618. _a.persistenceManager = _d.sent();
  2619. if (this._deleted) {
  2620. return [2 /*return*/];
  2621. }
  2622. if (!((_b = this._popupRedirectResolver) === null || _b === void 0 ? void 0 : _b._shouldInitProactively)) return [3 /*break*/, 5];
  2623. _d.label = 2;
  2624. case 2:
  2625. _d.trys.push([2, 4, , 5]);
  2626. return [4 /*yield*/, this._popupRedirectResolver._initialize(this)];
  2627. case 3:
  2628. _d.sent();
  2629. return [3 /*break*/, 5];
  2630. case 4:
  2631. _d.sent();
  2632. return [3 /*break*/, 5];
  2633. case 5: return [4 /*yield*/, this.initializeCurrentUser(popupRedirectResolver)];
  2634. case 6:
  2635. _d.sent();
  2636. this.lastNotifiedUid = ((_c = this.currentUser) === null || _c === void 0 ? void 0 : _c.uid) || null;
  2637. if (this._deleted) {
  2638. return [2 /*return*/];
  2639. }
  2640. this._isInitialized = true;
  2641. return [2 /*return*/];
  2642. }
  2643. });
  2644. }); });
  2645. return this._initializationPromise;
  2646. };
  2647. /**
  2648. * If the persistence is changed in another window, the user manager will let us know
  2649. */
  2650. AuthImpl.prototype._onStorageEvent = function () {
  2651. return tslib.__awaiter(this, void 0, void 0, function () {
  2652. var user;
  2653. return tslib.__generator(this, function (_a) {
  2654. switch (_a.label) {
  2655. case 0:
  2656. if (this._deleted) {
  2657. return [2 /*return*/];
  2658. }
  2659. return [4 /*yield*/, this.assertedPersistence.getCurrentUser()];
  2660. case 1:
  2661. user = _a.sent();
  2662. if (!this.currentUser && !user) {
  2663. // No change, do nothing (was signed out and remained signed out).
  2664. return [2 /*return*/];
  2665. }
  2666. if (!(this.currentUser && user && this.currentUser.uid === user.uid)) return [3 /*break*/, 3];
  2667. // Data update, simply copy data changes.
  2668. this._currentUser._assign(user);
  2669. // If tokens changed from previous user tokens, this will trigger
  2670. // notifyAuthListeners_.
  2671. return [4 /*yield*/, this.currentUser.getIdToken()];
  2672. case 2:
  2673. // If tokens changed from previous user tokens, this will trigger
  2674. // notifyAuthListeners_.
  2675. _a.sent();
  2676. return [2 /*return*/];
  2677. case 3:
  2678. // Update current Auth state. Either a new login or logout.
  2679. // Skip blocking callbacks, they should not apply to a change in another tab.
  2680. return [4 /*yield*/, this._updateCurrentUser(user, /* skipBeforeStateCallbacks */ true)];
  2681. case 4:
  2682. // Update current Auth state. Either a new login or logout.
  2683. // Skip blocking callbacks, they should not apply to a change in another tab.
  2684. _a.sent();
  2685. return [2 /*return*/];
  2686. }
  2687. });
  2688. });
  2689. };
  2690. AuthImpl.prototype.initializeCurrentUser = function (popupRedirectResolver) {
  2691. var _a;
  2692. return tslib.__awaiter(this, void 0, void 0, function () {
  2693. var previouslyStoredUser, futureCurrentUser, needsTocheckMiddleware, redirectUserEventId, storedUserEventId, result, e_2;
  2694. return tslib.__generator(this, function (_b) {
  2695. switch (_b.label) {
  2696. case 0: return [4 /*yield*/, this.assertedPersistence.getCurrentUser()];
  2697. case 1:
  2698. previouslyStoredUser = (_b.sent());
  2699. futureCurrentUser = previouslyStoredUser;
  2700. needsTocheckMiddleware = false;
  2701. if (!(popupRedirectResolver && this.config.authDomain)) return [3 /*break*/, 4];
  2702. return [4 /*yield*/, this.getOrInitRedirectPersistenceManager()];
  2703. case 2:
  2704. _b.sent();
  2705. redirectUserEventId = (_a = this.redirectUser) === null || _a === void 0 ? void 0 : _a._redirectEventId;
  2706. storedUserEventId = futureCurrentUser === null || futureCurrentUser === void 0 ? void 0 : futureCurrentUser._redirectEventId;
  2707. return [4 /*yield*/, this.tryRedirectSignIn(popupRedirectResolver)];
  2708. case 3:
  2709. result = _b.sent();
  2710. // If the stored user (i.e. the old "currentUser") has a redirectId that
  2711. // matches the redirect user, then we want to initially sign in with the
  2712. // new user object from result.
  2713. // TODO(samgho): More thoroughly test all of this
  2714. if ((!redirectUserEventId || redirectUserEventId === storedUserEventId) &&
  2715. (result === null || result === void 0 ? void 0 : result.user)) {
  2716. futureCurrentUser = result.user;
  2717. needsTocheckMiddleware = true;
  2718. }
  2719. _b.label = 4;
  2720. case 4:
  2721. // If no user in persistence, there is no current user. Set to null.
  2722. if (!futureCurrentUser) {
  2723. return [2 /*return*/, this.directlySetCurrentUser(null)];
  2724. }
  2725. if (!!futureCurrentUser._redirectEventId) return [3 /*break*/, 9];
  2726. if (!needsTocheckMiddleware) return [3 /*break*/, 8];
  2727. _b.label = 5;
  2728. case 5:
  2729. _b.trys.push([5, 7, , 8]);
  2730. return [4 /*yield*/, this.beforeStateQueue.runMiddleware(futureCurrentUser)];
  2731. case 6:
  2732. _b.sent();
  2733. return [3 /*break*/, 8];
  2734. case 7:
  2735. e_2 = _b.sent();
  2736. futureCurrentUser = previouslyStoredUser;
  2737. // We know this is available since the bit is only set when the
  2738. // resolver is available
  2739. this._popupRedirectResolver._overrideRedirectResult(this, function () {
  2740. return Promise.reject(e_2);
  2741. });
  2742. return [3 /*break*/, 8];
  2743. case 8:
  2744. if (futureCurrentUser) {
  2745. return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(futureCurrentUser)];
  2746. }
  2747. else {
  2748. return [2 /*return*/, this.directlySetCurrentUser(null)];
  2749. }
  2750. case 9:
  2751. _assert(this._popupRedirectResolver, this, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  2752. return [4 /*yield*/, this.getOrInitRedirectPersistenceManager()];
  2753. case 10:
  2754. _b.sent();
  2755. // If the redirect user's event ID matches the current user's event ID,
  2756. // DO NOT reload the current user, otherwise they'll be cleared from storage.
  2757. // This is important for the reauthenticateWithRedirect() flow.
  2758. if (this.redirectUser &&
  2759. this.redirectUser._redirectEventId === futureCurrentUser._redirectEventId) {
  2760. return [2 /*return*/, this.directlySetCurrentUser(futureCurrentUser)];
  2761. }
  2762. return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(futureCurrentUser)];
  2763. }
  2764. });
  2765. });
  2766. };
  2767. AuthImpl.prototype.tryRedirectSignIn = function (redirectResolver) {
  2768. return tslib.__awaiter(this, void 0, void 0, function () {
  2769. var result;
  2770. return tslib.__generator(this, function (_a) {
  2771. switch (_a.label) {
  2772. case 0:
  2773. result = null;
  2774. _a.label = 1;
  2775. case 1:
  2776. _a.trys.push([1, 3, , 5]);
  2777. return [4 /*yield*/, this._popupRedirectResolver._completeRedirectFn(this, redirectResolver, true)];
  2778. case 2:
  2779. // We know this._popupRedirectResolver is set since redirectResolver
  2780. // is passed in. The _completeRedirectFn expects the unwrapped extern.
  2781. result = _a.sent();
  2782. return [3 /*break*/, 5];
  2783. case 3:
  2784. _a.sent();
  2785. // Swallow any errors here; the code can retrieve them in
  2786. // getRedirectResult().
  2787. return [4 /*yield*/, this._setRedirectUser(null)];
  2788. case 4:
  2789. // Swallow any errors here; the code can retrieve them in
  2790. // getRedirectResult().
  2791. _a.sent();
  2792. return [3 /*break*/, 5];
  2793. case 5: return [2 /*return*/, result];
  2794. }
  2795. });
  2796. });
  2797. };
  2798. AuthImpl.prototype.reloadAndSetCurrentUserOrClear = function (user) {
  2799. return tslib.__awaiter(this, void 0, void 0, function () {
  2800. var e_4;
  2801. return tslib.__generator(this, function (_a) {
  2802. switch (_a.label) {
  2803. case 0:
  2804. _a.trys.push([0, 2, , 3]);
  2805. return [4 /*yield*/, _reloadWithoutSaving(user)];
  2806. case 1:
  2807. _a.sent();
  2808. return [3 /*break*/, 3];
  2809. case 2:
  2810. e_4 = _a.sent();
  2811. if ((e_4 === null || e_4 === void 0 ? void 0 : e_4.code) !==
  2812. "auth/".concat("network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */)) {
  2813. // Something's wrong with the user's token. Log them out and remove
  2814. // them from storage
  2815. return [2 /*return*/, this.directlySetCurrentUser(null)];
  2816. }
  2817. return [3 /*break*/, 3];
  2818. case 3: return [2 /*return*/, this.directlySetCurrentUser(user)];
  2819. }
  2820. });
  2821. });
  2822. };
  2823. AuthImpl.prototype.useDeviceLanguage = function () {
  2824. this.languageCode = _getUserLanguage();
  2825. };
  2826. AuthImpl.prototype._delete = function () {
  2827. return tslib.__awaiter(this, void 0, void 0, function () {
  2828. return tslib.__generator(this, function (_a) {
  2829. this._deleted = true;
  2830. return [2 /*return*/];
  2831. });
  2832. });
  2833. };
  2834. AuthImpl.prototype.updateCurrentUser = function (userExtern) {
  2835. return tslib.__awaiter(this, void 0, void 0, function () {
  2836. var user;
  2837. return tslib.__generator(this, function (_a) {
  2838. user = userExtern
  2839. ? util.getModularInstance(userExtern)
  2840. : null;
  2841. if (user) {
  2842. _assert(user.auth.config.apiKey === this.config.apiKey, this, "invalid-user-token" /* AuthErrorCode.INVALID_AUTH */);
  2843. }
  2844. return [2 /*return*/, this._updateCurrentUser(user && user._clone(this))];
  2845. });
  2846. });
  2847. };
  2848. AuthImpl.prototype._updateCurrentUser = function (user, skipBeforeStateCallbacks) {
  2849. if (skipBeforeStateCallbacks === void 0) { skipBeforeStateCallbacks = false; }
  2850. return tslib.__awaiter(this, void 0, void 0, function () {
  2851. var _this = this;
  2852. return tslib.__generator(this, function (_a) {
  2853. switch (_a.label) {
  2854. case 0:
  2855. if (this._deleted) {
  2856. return [2 /*return*/];
  2857. }
  2858. if (user) {
  2859. _assert(this.tenantId === user.tenantId, this, "tenant-id-mismatch" /* AuthErrorCode.TENANT_ID_MISMATCH */);
  2860. }
  2861. if (!!skipBeforeStateCallbacks) return [3 /*break*/, 2];
  2862. return [4 /*yield*/, this.beforeStateQueue.runMiddleware(user)];
  2863. case 1:
  2864. _a.sent();
  2865. _a.label = 2;
  2866. case 2: return [2 /*return*/, this.queue(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  2867. return tslib.__generator(this, function (_a) {
  2868. switch (_a.label) {
  2869. case 0: return [4 /*yield*/, this.directlySetCurrentUser(user)];
  2870. case 1:
  2871. _a.sent();
  2872. this.notifyAuthListeners();
  2873. return [2 /*return*/];
  2874. }
  2875. });
  2876. }); })];
  2877. }
  2878. });
  2879. });
  2880. };
  2881. AuthImpl.prototype.signOut = function () {
  2882. return tslib.__awaiter(this, void 0, void 0, function () {
  2883. return tslib.__generator(this, function (_a) {
  2884. switch (_a.label) {
  2885. case 0:
  2886. // Run first, to block _setRedirectUser() if any callbacks fail.
  2887. return [4 /*yield*/, this.beforeStateQueue.runMiddleware(null)];
  2888. case 1:
  2889. // Run first, to block _setRedirectUser() if any callbacks fail.
  2890. _a.sent();
  2891. if (!(this.redirectPersistenceManager || this._popupRedirectResolver)) return [3 /*break*/, 3];
  2892. return [4 /*yield*/, this._setRedirectUser(null)];
  2893. case 2:
  2894. _a.sent();
  2895. _a.label = 3;
  2896. case 3:
  2897. // Prevent callbacks from being called again in _updateCurrentUser, as
  2898. // they were already called in the first line.
  2899. return [2 /*return*/, this._updateCurrentUser(null, /* skipBeforeStateCallbacks */ true)];
  2900. }
  2901. });
  2902. });
  2903. };
  2904. AuthImpl.prototype.setPersistence = function (persistence) {
  2905. var _this = this;
  2906. return this.queue(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  2907. return tslib.__generator(this, function (_a) {
  2908. switch (_a.label) {
  2909. case 0: return [4 /*yield*/, this.assertedPersistence.setPersistence(_getInstance(persistence))];
  2910. case 1:
  2911. _a.sent();
  2912. return [2 /*return*/];
  2913. }
  2914. });
  2915. }); });
  2916. };
  2917. AuthImpl.prototype._getPersistence = function () {
  2918. return this.assertedPersistence.persistence.type;
  2919. };
  2920. AuthImpl.prototype._updateErrorMap = function (errorMap) {
  2921. this._errorFactory = new util.ErrorFactory('auth', 'Firebase', errorMap());
  2922. };
  2923. AuthImpl.prototype.onAuthStateChanged = function (nextOrObserver, error, completed) {
  2924. return this.registerStateListener(this.authStateSubscription, nextOrObserver, error, completed);
  2925. };
  2926. AuthImpl.prototype.beforeAuthStateChanged = function (callback, onAbort) {
  2927. return this.beforeStateQueue.pushCallback(callback, onAbort);
  2928. };
  2929. AuthImpl.prototype.onIdTokenChanged = function (nextOrObserver, error, completed) {
  2930. return this.registerStateListener(this.idTokenSubscription, nextOrObserver, error, completed);
  2931. };
  2932. AuthImpl.prototype.toJSON = function () {
  2933. var _a;
  2934. return {
  2935. apiKey: this.config.apiKey,
  2936. authDomain: this.config.authDomain,
  2937. appName: this.name,
  2938. currentUser: (_a = this._currentUser) === null || _a === void 0 ? void 0 : _a.toJSON()
  2939. };
  2940. };
  2941. AuthImpl.prototype._setRedirectUser = function (user, popupRedirectResolver) {
  2942. return tslib.__awaiter(this, void 0, void 0, function () {
  2943. var redirectManager;
  2944. return tslib.__generator(this, function (_a) {
  2945. switch (_a.label) {
  2946. case 0: return [4 /*yield*/, this.getOrInitRedirectPersistenceManager(popupRedirectResolver)];
  2947. case 1:
  2948. redirectManager = _a.sent();
  2949. return [2 /*return*/, user === null
  2950. ? redirectManager.removeCurrentUser()
  2951. : redirectManager.setCurrentUser(user)];
  2952. }
  2953. });
  2954. });
  2955. };
  2956. AuthImpl.prototype.getOrInitRedirectPersistenceManager = function (popupRedirectResolver) {
  2957. return tslib.__awaiter(this, void 0, void 0, function () {
  2958. var resolver, _a, _b;
  2959. return tslib.__generator(this, function (_c) {
  2960. switch (_c.label) {
  2961. case 0:
  2962. if (!!this.redirectPersistenceManager) return [3 /*break*/, 3];
  2963. resolver = (popupRedirectResolver && _getInstance(popupRedirectResolver)) ||
  2964. this._popupRedirectResolver;
  2965. _assert(resolver, this, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  2966. _a = this;
  2967. return [4 /*yield*/, PersistenceUserManager.create(this, [_getInstance(resolver._redirectPersistence)], "redirectUser" /* KeyName.REDIRECT_USER */)];
  2968. case 1:
  2969. _a.redirectPersistenceManager = _c.sent();
  2970. _b = this;
  2971. return [4 /*yield*/, this.redirectPersistenceManager.getCurrentUser()];
  2972. case 2:
  2973. _b.redirectUser =
  2974. _c.sent();
  2975. _c.label = 3;
  2976. case 3: return [2 /*return*/, this.redirectPersistenceManager];
  2977. }
  2978. });
  2979. });
  2980. };
  2981. AuthImpl.prototype._redirectUserForId = function (id) {
  2982. var _a, _b;
  2983. return tslib.__awaiter(this, void 0, void 0, function () {
  2984. var _this = this;
  2985. return tslib.__generator(this, function (_c) {
  2986. switch (_c.label) {
  2987. case 0:
  2988. if (!this._isInitialized) return [3 /*break*/, 2];
  2989. return [4 /*yield*/, this.queue(function () { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
  2990. return [2 /*return*/];
  2991. }); }); })];
  2992. case 1:
  2993. _c.sent();
  2994. _c.label = 2;
  2995. case 2:
  2996. if (((_a = this._currentUser) === null || _a === void 0 ? void 0 : _a._redirectEventId) === id) {
  2997. return [2 /*return*/, this._currentUser];
  2998. }
  2999. if (((_b = this.redirectUser) === null || _b === void 0 ? void 0 : _b._redirectEventId) === id) {
  3000. return [2 /*return*/, this.redirectUser];
  3001. }
  3002. return [2 /*return*/, null];
  3003. }
  3004. });
  3005. });
  3006. };
  3007. AuthImpl.prototype._persistUserIfCurrent = function (user) {
  3008. return tslib.__awaiter(this, void 0, void 0, function () {
  3009. var _this = this;
  3010. return tslib.__generator(this, function (_a) {
  3011. if (user === this.currentUser) {
  3012. return [2 /*return*/, this.queue(function () { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
  3013. return [2 /*return*/, this.directlySetCurrentUser(user)];
  3014. }); }); })];
  3015. }
  3016. return [2 /*return*/];
  3017. });
  3018. });
  3019. };
  3020. /** Notifies listeners only if the user is current */
  3021. AuthImpl.prototype._notifyListenersIfCurrent = function (user) {
  3022. if (user === this.currentUser) {
  3023. this.notifyAuthListeners();
  3024. }
  3025. };
  3026. AuthImpl.prototype._key = function () {
  3027. return "".concat(this.config.authDomain, ":").concat(this.config.apiKey, ":").concat(this.name);
  3028. };
  3029. AuthImpl.prototype._startProactiveRefresh = function () {
  3030. this.isProactiveRefreshEnabled = true;
  3031. if (this.currentUser) {
  3032. this._currentUser._startProactiveRefresh();
  3033. }
  3034. };
  3035. AuthImpl.prototype._stopProactiveRefresh = function () {
  3036. this.isProactiveRefreshEnabled = false;
  3037. if (this.currentUser) {
  3038. this._currentUser._stopProactiveRefresh();
  3039. }
  3040. };
  3041. Object.defineProperty(AuthImpl.prototype, "_currentUser", {
  3042. /** Returns the current user cast as the internal type */
  3043. get: function () {
  3044. return this.currentUser;
  3045. },
  3046. enumerable: false,
  3047. configurable: true
  3048. });
  3049. AuthImpl.prototype.notifyAuthListeners = function () {
  3050. var _a, _b;
  3051. if (!this._isInitialized) {
  3052. return;
  3053. }
  3054. this.idTokenSubscription.next(this.currentUser);
  3055. var currentUid = (_b = (_a = this.currentUser) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null;
  3056. if (this.lastNotifiedUid !== currentUid) {
  3057. this.lastNotifiedUid = currentUid;
  3058. this.authStateSubscription.next(this.currentUser);
  3059. }
  3060. };
  3061. AuthImpl.prototype.registerStateListener = function (subscription, nextOrObserver, error, completed) {
  3062. var _this = this;
  3063. if (this._deleted) {
  3064. return function () { };
  3065. }
  3066. var cb = typeof nextOrObserver === 'function'
  3067. ? nextOrObserver
  3068. : nextOrObserver.next.bind(nextOrObserver);
  3069. var promise = this._isInitialized
  3070. ? Promise.resolve()
  3071. : this._initializationPromise;
  3072. _assert(promise, this, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  3073. // The callback needs to be called asynchronously per the spec.
  3074. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  3075. promise.then(function () { return cb(_this.currentUser); });
  3076. if (typeof nextOrObserver === 'function') {
  3077. return subscription.addObserver(nextOrObserver, error, completed);
  3078. }
  3079. else {
  3080. return subscription.addObserver(nextOrObserver);
  3081. }
  3082. };
  3083. /**
  3084. * Unprotected (from race conditions) method to set the current user. This
  3085. * should only be called from within a queued callback. This is necessary
  3086. * because the queue shouldn't rely on another queued callback.
  3087. */
  3088. AuthImpl.prototype.directlySetCurrentUser = function (user) {
  3089. return tslib.__awaiter(this, void 0, void 0, function () {
  3090. return tslib.__generator(this, function (_a) {
  3091. switch (_a.label) {
  3092. case 0:
  3093. if (this.currentUser && this.currentUser !== user) {
  3094. this._currentUser._stopProactiveRefresh();
  3095. }
  3096. if (user && this.isProactiveRefreshEnabled) {
  3097. user._startProactiveRefresh();
  3098. }
  3099. this.currentUser = user;
  3100. if (!user) return [3 /*break*/, 2];
  3101. return [4 /*yield*/, this.assertedPersistence.setCurrentUser(user)];
  3102. case 1:
  3103. _a.sent();
  3104. return [3 /*break*/, 4];
  3105. case 2: return [4 /*yield*/, this.assertedPersistence.removeCurrentUser()];
  3106. case 3:
  3107. _a.sent();
  3108. _a.label = 4;
  3109. case 4: return [2 /*return*/];
  3110. }
  3111. });
  3112. });
  3113. };
  3114. AuthImpl.prototype.queue = function (action) {
  3115. // In case something errors, the callback still should be called in order
  3116. // to keep the promise chain alive
  3117. this.operations = this.operations.then(action, action);
  3118. return this.operations;
  3119. };
  3120. Object.defineProperty(AuthImpl.prototype, "assertedPersistence", {
  3121. get: function () {
  3122. _assert(this.persistenceManager, this, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  3123. return this.persistenceManager;
  3124. },
  3125. enumerable: false,
  3126. configurable: true
  3127. });
  3128. AuthImpl.prototype._logFramework = function (framework) {
  3129. if (!framework || this.frameworks.includes(framework)) {
  3130. return;
  3131. }
  3132. this.frameworks.push(framework);
  3133. // Sort alphabetically so that "FirebaseCore-web,FirebaseUI-web" and
  3134. // "FirebaseUI-web,FirebaseCore-web" aren't viewed as different.
  3135. this.frameworks.sort();
  3136. this.clientVersion = _getClientVersion(this.config.clientPlatform, this._getFrameworks());
  3137. };
  3138. AuthImpl.prototype._getFrameworks = function () {
  3139. return this.frameworks;
  3140. };
  3141. AuthImpl.prototype._getAdditionalHeaders = function () {
  3142. var _a;
  3143. return tslib.__awaiter(this, void 0, void 0, function () {
  3144. var headers, heartbeatsHeader;
  3145. var _b;
  3146. return tslib.__generator(this, function (_c) {
  3147. switch (_c.label) {
  3148. case 0:
  3149. headers = (_b = {},
  3150. _b["X-Client-Version" /* HttpHeader.X_CLIENT_VERSION */] = this.clientVersion,
  3151. _b);
  3152. if (this.app.options.appId) {
  3153. headers["X-Firebase-gmpid" /* HttpHeader.X_FIREBASE_GMPID */] = this.app.options.appId;
  3154. }
  3155. return [4 /*yield*/, ((_a = this.heartbeatServiceProvider
  3156. .getImmediate({
  3157. optional: true
  3158. })) === null || _a === void 0 ? void 0 : _a.getHeartbeatsHeader())];
  3159. case 1:
  3160. heartbeatsHeader = _c.sent();
  3161. if (heartbeatsHeader) {
  3162. headers["X-Firebase-Client" /* HttpHeader.X_FIREBASE_CLIENT */] = heartbeatsHeader;
  3163. }
  3164. return [2 /*return*/, headers];
  3165. }
  3166. });
  3167. });
  3168. };
  3169. return AuthImpl;
  3170. }());
  3171. /**
  3172. * Method to be used to cast down to our private implmentation of Auth.
  3173. * It will also handle unwrapping from the compat type if necessary
  3174. *
  3175. * @param auth Auth object passed in from developer
  3176. */
  3177. function _castAuth(auth) {
  3178. return util.getModularInstance(auth);
  3179. }
  3180. /** Helper class to wrap subscriber logic */
  3181. var Subscription = /** @class */ (function () {
  3182. function Subscription(auth) {
  3183. var _this = this;
  3184. this.auth = auth;
  3185. this.observer = null;
  3186. this.addObserver = util.createSubscribe(function (observer) { return (_this.observer = observer); });
  3187. }
  3188. Object.defineProperty(Subscription.prototype, "next", {
  3189. get: function () {
  3190. _assert(this.observer, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  3191. return this.observer.next.bind(this.observer);
  3192. },
  3193. enumerable: false,
  3194. configurable: true
  3195. });
  3196. return Subscription;
  3197. }());
  3198. /**
  3199. * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
  3200. * Firebase Auth services.
  3201. *
  3202. * @remarks
  3203. * This must be called synchronously immediately following the first call to
  3204. * {@link initializeAuth}. Do not use with production credentials as emulator
  3205. * traffic is not encrypted.
  3206. *
  3207. *
  3208. * @example
  3209. * ```javascript
  3210. * connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
  3211. * ```
  3212. *
  3213. * @param auth - The {@link Auth} instance.
  3214. * @param url - The URL at which the emulator is running (eg, 'http://localhost:9099').
  3215. * @param options - Optional. `options.disableWarnings` defaults to `false`. Set it to
  3216. * `true` to disable the warning banner attached to the DOM.
  3217. *
  3218. * @public
  3219. */
  3220. function connectAuthEmulator(auth, url, options) {
  3221. var authInternal = _castAuth(auth);
  3222. _assert(authInternal._canInitEmulator, authInternal, "emulator-config-failed" /* AuthErrorCode.EMULATOR_CONFIG_FAILED */);
  3223. _assert(/^https?:\/\//.test(url), authInternal, "invalid-emulator-scheme" /* AuthErrorCode.INVALID_EMULATOR_SCHEME */);
  3224. var disableWarnings = !!(options === null || options === void 0 ? void 0 : options.disableWarnings);
  3225. var protocol = extractProtocol(url);
  3226. var _a = extractHostAndPort(url), host = _a.host, port = _a.port;
  3227. var portStr = port === null ? '' : ":".concat(port);
  3228. // Always replace path with "/" (even if input url had no path at all, or had a different one).
  3229. authInternal.config.emulator = { url: "".concat(protocol, "//").concat(host).concat(portStr, "/") };
  3230. authInternal.settings.appVerificationDisabledForTesting = true;
  3231. authInternal.emulatorConfig = Object.freeze({
  3232. host: host,
  3233. port: port,
  3234. protocol: protocol.replace(':', ''),
  3235. options: Object.freeze({ disableWarnings: disableWarnings })
  3236. });
  3237. if (!disableWarnings) {
  3238. emitEmulatorWarning();
  3239. }
  3240. }
  3241. function extractProtocol(url) {
  3242. var protocolEnd = url.indexOf(':');
  3243. return protocolEnd < 0 ? '' : url.substr(0, protocolEnd + 1);
  3244. }
  3245. function extractHostAndPort(url) {
  3246. var protocol = extractProtocol(url);
  3247. var authority = /(\/\/)?([^?#/]+)/.exec(url.substr(protocol.length)); // Between // and /, ? or #.
  3248. if (!authority) {
  3249. return { host: '', port: null };
  3250. }
  3251. var hostAndPort = authority[2].split('@').pop() || ''; // Strip out "username:password@".
  3252. var bracketedIPv6 = /^(\[[^\]]+\])(:|$)/.exec(hostAndPort);
  3253. if (bracketedIPv6) {
  3254. var host = bracketedIPv6[1];
  3255. return { host: host, port: parsePort(hostAndPort.substr(host.length + 1)) };
  3256. }
  3257. else {
  3258. var _a = hostAndPort.split(':'), host = _a[0], port = _a[1];
  3259. return { host: host, port: parsePort(port) };
  3260. }
  3261. }
  3262. function parsePort(portStr) {
  3263. if (!portStr) {
  3264. return null;
  3265. }
  3266. var port = Number(portStr);
  3267. if (isNaN(port)) {
  3268. return null;
  3269. }
  3270. return port;
  3271. }
  3272. function emitEmulatorWarning() {
  3273. function attachBanner() {
  3274. var el = document.createElement('p');
  3275. var sty = el.style;
  3276. el.innerText =
  3277. 'Running in emulator mode. Do not use with production credentials.';
  3278. sty.position = 'fixed';
  3279. sty.width = '100%';
  3280. sty.backgroundColor = '#ffffff';
  3281. sty.border = '.1em solid #000000';
  3282. sty.color = '#b50000';
  3283. sty.bottom = '0px';
  3284. sty.left = '0px';
  3285. sty.margin = '0px';
  3286. sty.zIndex = '10000';
  3287. sty.textAlign = 'center';
  3288. el.classList.add('firebase-emulator-warning');
  3289. document.body.appendChild(el);
  3290. }
  3291. if (typeof console !== 'undefined' && typeof console.info === 'function') {
  3292. console.info('WARNING: You are using the Auth Emulator,' +
  3293. ' which is intended for local testing only. Do not use with' +
  3294. ' production credentials.');
  3295. }
  3296. if (typeof window !== 'undefined' && typeof document !== 'undefined') {
  3297. if (document.readyState === 'loading') {
  3298. window.addEventListener('DOMContentLoaded', attachBanner);
  3299. }
  3300. else {
  3301. attachBanner();
  3302. }
  3303. }
  3304. }
  3305. /**
  3306. * @license
  3307. * Copyright 2020 Google LLC
  3308. *
  3309. * Licensed under the Apache License, Version 2.0 (the "License");
  3310. * you may not use this file except in compliance with the License.
  3311. * You may obtain a copy of the License at
  3312. *
  3313. * http://www.apache.org/licenses/LICENSE-2.0
  3314. *
  3315. * Unless required by applicable law or agreed to in writing, software
  3316. * distributed under the License is distributed on an "AS IS" BASIS,
  3317. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3318. * See the License for the specific language governing permissions and
  3319. * limitations under the License.
  3320. */
  3321. /**
  3322. * Interface that represents the credentials returned by an {@link AuthProvider}.
  3323. *
  3324. * @remarks
  3325. * Implementations specify the details about each auth provider's credential requirements.
  3326. *
  3327. * @public
  3328. */
  3329. var AuthCredential = /** @class */ (function () {
  3330. /** @internal */
  3331. function AuthCredential(
  3332. /**
  3333. * The authentication provider ID for the credential.
  3334. *
  3335. * @remarks
  3336. * For example, 'facebook.com', or 'google.com'.
  3337. */
  3338. providerId,
  3339. /**
  3340. * The authentication sign in method for the credential.
  3341. *
  3342. * @remarks
  3343. * For example, {@link SignInMethod}.EMAIL_PASSWORD, or
  3344. * {@link SignInMethod}.EMAIL_LINK. This corresponds to the sign-in method
  3345. * identifier as returned in {@link fetchSignInMethodsForEmail}.
  3346. */
  3347. signInMethod) {
  3348. this.providerId = providerId;
  3349. this.signInMethod = signInMethod;
  3350. }
  3351. /**
  3352. * Returns a JSON-serializable representation of this object.
  3353. *
  3354. * @returns a JSON-serializable representation of this object.
  3355. */
  3356. AuthCredential.prototype.toJSON = function () {
  3357. return debugFail('not implemented');
  3358. };
  3359. /** @internal */
  3360. AuthCredential.prototype._getIdTokenResponse = function (_auth) {
  3361. return debugFail('not implemented');
  3362. };
  3363. /** @internal */
  3364. AuthCredential.prototype._linkToIdToken = function (_auth, _idToken) {
  3365. return debugFail('not implemented');
  3366. };
  3367. /** @internal */
  3368. AuthCredential.prototype._getReauthenticationResolver = function (_auth) {
  3369. return debugFail('not implemented');
  3370. };
  3371. return AuthCredential;
  3372. }());
  3373. /**
  3374. * @license
  3375. * Copyright 2020 Google LLC
  3376. *
  3377. * Licensed under the Apache License, Version 2.0 (the "License");
  3378. * you may not use this file except in compliance with the License.
  3379. * You may obtain a copy of the License at
  3380. *
  3381. * http://www.apache.org/licenses/LICENSE-2.0
  3382. *
  3383. * Unless required by applicable law or agreed to in writing, software
  3384. * distributed under the License is distributed on an "AS IS" BASIS,
  3385. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3386. * See the License for the specific language governing permissions and
  3387. * limitations under the License.
  3388. */
  3389. function resetPassword(auth, request) {
  3390. return tslib.__awaiter(this, void 0, void 0, function () {
  3391. return tslib.__generator(this, function (_a) {
  3392. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:resetPassword" /* Endpoint.RESET_PASSWORD */, _addTidIfNecessary(auth, request))];
  3393. });
  3394. });
  3395. }
  3396. function updateEmailPassword(auth, request) {
  3397. return tslib.__awaiter(this, void 0, void 0, function () {
  3398. return tslib.__generator(this, function (_a) {
  3399. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:update" /* Endpoint.SET_ACCOUNT_INFO */, request)];
  3400. });
  3401. });
  3402. }
  3403. function applyActionCode$1(auth, request) {
  3404. return tslib.__awaiter(this, void 0, void 0, function () {
  3405. return tslib.__generator(this, function (_a) {
  3406. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:update" /* Endpoint.SET_ACCOUNT_INFO */, _addTidIfNecessary(auth, request))];
  3407. });
  3408. });
  3409. }
  3410. /**
  3411. * @license
  3412. * Copyright 2020 Google LLC
  3413. *
  3414. * Licensed under the Apache License, Version 2.0 (the "License");
  3415. * you may not use this file except in compliance with the License.
  3416. * You may obtain a copy of the License at
  3417. *
  3418. * http://www.apache.org/licenses/LICENSE-2.0
  3419. *
  3420. * Unless required by applicable law or agreed to in writing, software
  3421. * distributed under the License is distributed on an "AS IS" BASIS,
  3422. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3423. * See the License for the specific language governing permissions and
  3424. * limitations under the License.
  3425. */
  3426. function signInWithPassword(auth, request) {
  3427. return tslib.__awaiter(this, void 0, void 0, function () {
  3428. return tslib.__generator(this, function (_a) {
  3429. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithPassword" /* Endpoint.SIGN_IN_WITH_PASSWORD */, _addTidIfNecessary(auth, request))];
  3430. });
  3431. });
  3432. }
  3433. function sendOobCode(auth, request) {
  3434. return tslib.__awaiter(this, void 0, void 0, function () {
  3435. return tslib.__generator(this, function (_a) {
  3436. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:sendOobCode" /* Endpoint.SEND_OOB_CODE */, _addTidIfNecessary(auth, request))];
  3437. });
  3438. });
  3439. }
  3440. function sendEmailVerification$1(auth, request) {
  3441. return tslib.__awaiter(this, void 0, void 0, function () {
  3442. return tslib.__generator(this, function (_a) {
  3443. return [2 /*return*/, sendOobCode(auth, request)];
  3444. });
  3445. });
  3446. }
  3447. function sendPasswordResetEmail$1(auth, request) {
  3448. return tslib.__awaiter(this, void 0, void 0, function () {
  3449. return tslib.__generator(this, function (_a) {
  3450. return [2 /*return*/, sendOobCode(auth, request)];
  3451. });
  3452. });
  3453. }
  3454. function sendSignInLinkToEmail$1(auth, request) {
  3455. return tslib.__awaiter(this, void 0, void 0, function () {
  3456. return tslib.__generator(this, function (_a) {
  3457. return [2 /*return*/, sendOobCode(auth, request)];
  3458. });
  3459. });
  3460. }
  3461. function verifyAndChangeEmail(auth, request) {
  3462. return tslib.__awaiter(this, void 0, void 0, function () {
  3463. return tslib.__generator(this, function (_a) {
  3464. return [2 /*return*/, sendOobCode(auth, request)];
  3465. });
  3466. });
  3467. }
  3468. /**
  3469. * @license
  3470. * Copyright 2020 Google LLC
  3471. *
  3472. * Licensed under the Apache License, Version 2.0 (the "License");
  3473. * you may not use this file except in compliance with the License.
  3474. * You may obtain a copy of the License at
  3475. *
  3476. * http://www.apache.org/licenses/LICENSE-2.0
  3477. *
  3478. * Unless required by applicable law or agreed to in writing, software
  3479. * distributed under the License is distributed on an "AS IS" BASIS,
  3480. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3481. * See the License for the specific language governing permissions and
  3482. * limitations under the License.
  3483. */
  3484. function signInWithEmailLink$1(auth, request) {
  3485. return tslib.__awaiter(this, void 0, void 0, function () {
  3486. return tslib.__generator(this, function (_a) {
  3487. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithEmailLink" /* Endpoint.SIGN_IN_WITH_EMAIL_LINK */, _addTidIfNecessary(auth, request))];
  3488. });
  3489. });
  3490. }
  3491. function signInWithEmailLinkForLinking(auth, request) {
  3492. return tslib.__awaiter(this, void 0, void 0, function () {
  3493. return tslib.__generator(this, function (_a) {
  3494. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithEmailLink" /* Endpoint.SIGN_IN_WITH_EMAIL_LINK */, _addTidIfNecessary(auth, request))];
  3495. });
  3496. });
  3497. }
  3498. /**
  3499. * @license
  3500. * Copyright 2020 Google LLC
  3501. *
  3502. * Licensed under the Apache License, Version 2.0 (the "License");
  3503. * you may not use this file except in compliance with the License.
  3504. * You may obtain a copy of the License at
  3505. *
  3506. * http://www.apache.org/licenses/LICENSE-2.0
  3507. *
  3508. * Unless required by applicable law or agreed to in writing, software
  3509. * distributed under the License is distributed on an "AS IS" BASIS,
  3510. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3511. * See the License for the specific language governing permissions and
  3512. * limitations under the License.
  3513. */
  3514. /**
  3515. * Interface that represents the credentials returned by {@link EmailAuthProvider} for
  3516. * {@link ProviderId}.PASSWORD
  3517. *
  3518. * @remarks
  3519. * Covers both {@link SignInMethod}.EMAIL_PASSWORD and
  3520. * {@link SignInMethod}.EMAIL_LINK.
  3521. *
  3522. * @public
  3523. */
  3524. var EmailAuthCredential = /** @class */ (function (_super) {
  3525. tslib.__extends(EmailAuthCredential, _super);
  3526. /** @internal */
  3527. function EmailAuthCredential(
  3528. /** @internal */
  3529. _email,
  3530. /** @internal */
  3531. _password, signInMethod,
  3532. /** @internal */
  3533. _tenantId) {
  3534. if (_tenantId === void 0) { _tenantId = null; }
  3535. var _this = _super.call(this, "password" /* ProviderId.PASSWORD */, signInMethod) || this;
  3536. _this._email = _email;
  3537. _this._password = _password;
  3538. _this._tenantId = _tenantId;
  3539. return _this;
  3540. }
  3541. /** @internal */
  3542. EmailAuthCredential._fromEmailAndPassword = function (email, password) {
  3543. return new EmailAuthCredential(email, password, "password" /* SignInMethod.EMAIL_PASSWORD */);
  3544. };
  3545. /** @internal */
  3546. EmailAuthCredential._fromEmailAndCode = function (email, oobCode, tenantId) {
  3547. if (tenantId === void 0) { tenantId = null; }
  3548. return new EmailAuthCredential(email, oobCode, "emailLink" /* SignInMethod.EMAIL_LINK */, tenantId);
  3549. };
  3550. /** {@inheritdoc AuthCredential.toJSON} */
  3551. EmailAuthCredential.prototype.toJSON = function () {
  3552. return {
  3553. email: this._email,
  3554. password: this._password,
  3555. signInMethod: this.signInMethod,
  3556. tenantId: this._tenantId
  3557. };
  3558. };
  3559. /**
  3560. * Static method to deserialize a JSON representation of an object into an {@link AuthCredential}.
  3561. *
  3562. * @param json - Either `object` or the stringified representation of the object. When string is
  3563. * provided, `JSON.parse` would be called first.
  3564. *
  3565. * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
  3566. */
  3567. EmailAuthCredential.fromJSON = function (json) {
  3568. var obj = typeof json === 'string' ? JSON.parse(json) : json;
  3569. if ((obj === null || obj === void 0 ? void 0 : obj.email) && (obj === null || obj === void 0 ? void 0 : obj.password)) {
  3570. if (obj.signInMethod === "password" /* SignInMethod.EMAIL_PASSWORD */) {
  3571. return this._fromEmailAndPassword(obj.email, obj.password);
  3572. }
  3573. else if (obj.signInMethod === "emailLink" /* SignInMethod.EMAIL_LINK */) {
  3574. return this._fromEmailAndCode(obj.email, obj.password, obj.tenantId);
  3575. }
  3576. }
  3577. return null;
  3578. };
  3579. /** @internal */
  3580. EmailAuthCredential.prototype._getIdTokenResponse = function (auth) {
  3581. return tslib.__awaiter(this, void 0, void 0, function () {
  3582. return tslib.__generator(this, function (_a) {
  3583. switch (this.signInMethod) {
  3584. case "password" /* SignInMethod.EMAIL_PASSWORD */:
  3585. return [2 /*return*/, signInWithPassword(auth, {
  3586. returnSecureToken: true,
  3587. email: this._email,
  3588. password: this._password
  3589. })];
  3590. case "emailLink" /* SignInMethod.EMAIL_LINK */:
  3591. return [2 /*return*/, signInWithEmailLink$1(auth, {
  3592. email: this._email,
  3593. oobCode: this._password
  3594. })];
  3595. default:
  3596. _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  3597. }
  3598. return [2 /*return*/];
  3599. });
  3600. });
  3601. };
  3602. /** @internal */
  3603. EmailAuthCredential.prototype._linkToIdToken = function (auth, idToken) {
  3604. return tslib.__awaiter(this, void 0, void 0, function () {
  3605. return tslib.__generator(this, function (_a) {
  3606. switch (this.signInMethod) {
  3607. case "password" /* SignInMethod.EMAIL_PASSWORD */:
  3608. return [2 /*return*/, updateEmailPassword(auth, {
  3609. idToken: idToken,
  3610. returnSecureToken: true,
  3611. email: this._email,
  3612. password: this._password
  3613. })];
  3614. case "emailLink" /* SignInMethod.EMAIL_LINK */:
  3615. return [2 /*return*/, signInWithEmailLinkForLinking(auth, {
  3616. idToken: idToken,
  3617. email: this._email,
  3618. oobCode: this._password
  3619. })];
  3620. default:
  3621. _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  3622. }
  3623. return [2 /*return*/];
  3624. });
  3625. });
  3626. };
  3627. /** @internal */
  3628. EmailAuthCredential.prototype._getReauthenticationResolver = function (auth) {
  3629. return this._getIdTokenResponse(auth);
  3630. };
  3631. return EmailAuthCredential;
  3632. }(AuthCredential));
  3633. /**
  3634. * @license
  3635. * Copyright 2020 Google LLC
  3636. *
  3637. * Licensed under the Apache License, Version 2.0 (the "License");
  3638. * you may not use this file except in compliance with the License.
  3639. * You may obtain a copy of the License at
  3640. *
  3641. * http://www.apache.org/licenses/LICENSE-2.0
  3642. *
  3643. * Unless required by applicable law or agreed to in writing, software
  3644. * distributed under the License is distributed on an "AS IS" BASIS,
  3645. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3646. * See the License for the specific language governing permissions and
  3647. * limitations under the License.
  3648. */
  3649. function signInWithIdp(auth, request) {
  3650. return tslib.__awaiter(this, void 0, void 0, function () {
  3651. return tslib.__generator(this, function (_a) {
  3652. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithIdp" /* Endpoint.SIGN_IN_WITH_IDP */, _addTidIfNecessary(auth, request))];
  3653. });
  3654. });
  3655. }
  3656. /**
  3657. * @license
  3658. * Copyright 2020 Google LLC
  3659. *
  3660. * Licensed under the Apache License, Version 2.0 (the "License");
  3661. * you may not use this file except in compliance with the License.
  3662. * You may obtain a copy of the License at
  3663. *
  3664. * http://www.apache.org/licenses/LICENSE-2.0
  3665. *
  3666. * Unless required by applicable law or agreed to in writing, software
  3667. * distributed under the License is distributed on an "AS IS" BASIS,
  3668. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3669. * See the License for the specific language governing permissions and
  3670. * limitations under the License.
  3671. */
  3672. var IDP_REQUEST_URI$1 = 'http://localhost';
  3673. /**
  3674. * Represents the OAuth credentials returned by an {@link OAuthProvider}.
  3675. *
  3676. * @remarks
  3677. * Implementations specify the details about each auth provider's credential requirements.
  3678. *
  3679. * @public
  3680. */
  3681. var OAuthCredential = /** @class */ (function (_super) {
  3682. tslib.__extends(OAuthCredential, _super);
  3683. function OAuthCredential() {
  3684. var _this = _super !== null && _super.apply(this, arguments) || this;
  3685. _this.pendingToken = null;
  3686. return _this;
  3687. }
  3688. /** @internal */
  3689. OAuthCredential._fromParams = function (params) {
  3690. var cred = new OAuthCredential(params.providerId, params.signInMethod);
  3691. if (params.idToken || params.accessToken) {
  3692. // OAuth 2 and either ID token or access token.
  3693. if (params.idToken) {
  3694. cred.idToken = params.idToken;
  3695. }
  3696. if (params.accessToken) {
  3697. cred.accessToken = params.accessToken;
  3698. }
  3699. // Add nonce if available and no pendingToken is present.
  3700. if (params.nonce && !params.pendingToken) {
  3701. cred.nonce = params.nonce;
  3702. }
  3703. if (params.pendingToken) {
  3704. cred.pendingToken = params.pendingToken;
  3705. }
  3706. }
  3707. else if (params.oauthToken && params.oauthTokenSecret) {
  3708. // OAuth 1 and OAuth token with token secret
  3709. cred.accessToken = params.oauthToken;
  3710. cred.secret = params.oauthTokenSecret;
  3711. }
  3712. else {
  3713. _fail("argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  3714. }
  3715. return cred;
  3716. };
  3717. /** {@inheritdoc AuthCredential.toJSON} */
  3718. OAuthCredential.prototype.toJSON = function () {
  3719. return {
  3720. idToken: this.idToken,
  3721. accessToken: this.accessToken,
  3722. secret: this.secret,
  3723. nonce: this.nonce,
  3724. pendingToken: this.pendingToken,
  3725. providerId: this.providerId,
  3726. signInMethod: this.signInMethod
  3727. };
  3728. };
  3729. /**
  3730. * Static method to deserialize a JSON representation of an object into an
  3731. * {@link AuthCredential}.
  3732. *
  3733. * @param json - Input can be either Object or the stringified representation of the object.
  3734. * When string is provided, JSON.parse would be called first.
  3735. *
  3736. * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
  3737. */
  3738. OAuthCredential.fromJSON = function (json) {
  3739. var obj = typeof json === 'string' ? JSON.parse(json) : json;
  3740. var providerId = obj.providerId, signInMethod = obj.signInMethod, rest = tslib.__rest(obj, ["providerId", "signInMethod"]);
  3741. if (!providerId || !signInMethod) {
  3742. return null;
  3743. }
  3744. var cred = new OAuthCredential(providerId, signInMethod);
  3745. cred.idToken = rest.idToken || undefined;
  3746. cred.accessToken = rest.accessToken || undefined;
  3747. cred.secret = rest.secret;
  3748. cred.nonce = rest.nonce;
  3749. cred.pendingToken = rest.pendingToken || null;
  3750. return cred;
  3751. };
  3752. /** @internal */
  3753. OAuthCredential.prototype._getIdTokenResponse = function (auth) {
  3754. var request = this.buildRequest();
  3755. return signInWithIdp(auth, request);
  3756. };
  3757. /** @internal */
  3758. OAuthCredential.prototype._linkToIdToken = function (auth, idToken) {
  3759. var request = this.buildRequest();
  3760. request.idToken = idToken;
  3761. return signInWithIdp(auth, request);
  3762. };
  3763. /** @internal */
  3764. OAuthCredential.prototype._getReauthenticationResolver = function (auth) {
  3765. var request = this.buildRequest();
  3766. request.autoCreate = false;
  3767. return signInWithIdp(auth, request);
  3768. };
  3769. OAuthCredential.prototype.buildRequest = function () {
  3770. var request = {
  3771. requestUri: IDP_REQUEST_URI$1,
  3772. returnSecureToken: true
  3773. };
  3774. if (this.pendingToken) {
  3775. request.pendingToken = this.pendingToken;
  3776. }
  3777. else {
  3778. var postBody = {};
  3779. if (this.idToken) {
  3780. postBody['id_token'] = this.idToken;
  3781. }
  3782. if (this.accessToken) {
  3783. postBody['access_token'] = this.accessToken;
  3784. }
  3785. if (this.secret) {
  3786. postBody['oauth_token_secret'] = this.secret;
  3787. }
  3788. postBody['providerId'] = this.providerId;
  3789. if (this.nonce && !this.pendingToken) {
  3790. postBody['nonce'] = this.nonce;
  3791. }
  3792. request.postBody = util.querystring(postBody);
  3793. }
  3794. return request;
  3795. };
  3796. return OAuthCredential;
  3797. }(AuthCredential));
  3798. /**
  3799. * @license
  3800. * Copyright 2020 Google LLC
  3801. *
  3802. * Licensed under the Apache License, Version 2.0 (the "License");
  3803. * you may not use this file except in compliance with the License.
  3804. * You may obtain a copy of the License at
  3805. *
  3806. * http://www.apache.org/licenses/LICENSE-2.0
  3807. *
  3808. * Unless required by applicable law or agreed to in writing, software
  3809. * distributed under the License is distributed on an "AS IS" BASIS,
  3810. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3811. * See the License for the specific language governing permissions and
  3812. * limitations under the License.
  3813. */
  3814. var _a;
  3815. function signInWithPhoneNumber$1(auth, request) {
  3816. return tslib.__awaiter(this, void 0, void 0, function () {
  3817. return tslib.__generator(this, function (_a) {
  3818. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithPhoneNumber" /* Endpoint.SIGN_IN_WITH_PHONE_NUMBER */, _addTidIfNecessary(auth, request))];
  3819. });
  3820. });
  3821. }
  3822. function linkWithPhoneNumber$1(auth, request) {
  3823. return tslib.__awaiter(this, void 0, void 0, function () {
  3824. var response;
  3825. return tslib.__generator(this, function (_a) {
  3826. switch (_a.label) {
  3827. case 0: return [4 /*yield*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithPhoneNumber" /* Endpoint.SIGN_IN_WITH_PHONE_NUMBER */, _addTidIfNecessary(auth, request))];
  3828. case 1:
  3829. response = _a.sent();
  3830. if (response.temporaryProof) {
  3831. throw _makeTaggedError(auth, "account-exists-with-different-credential" /* AuthErrorCode.NEED_CONFIRMATION */, response);
  3832. }
  3833. return [2 /*return*/, response];
  3834. }
  3835. });
  3836. });
  3837. }
  3838. var VERIFY_PHONE_NUMBER_FOR_EXISTING_ERROR_MAP_ = (_a = {},
  3839. _a["USER_NOT_FOUND" /* ServerError.USER_NOT_FOUND */] = "user-not-found" /* AuthErrorCode.USER_DELETED */,
  3840. _a);
  3841. function verifyPhoneNumberForExisting(auth, request) {
  3842. return tslib.__awaiter(this, void 0, void 0, function () {
  3843. var apiRequest;
  3844. return tslib.__generator(this, function (_a) {
  3845. apiRequest = tslib.__assign(tslib.__assign({}, request), { operation: 'REAUTH' });
  3846. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithPhoneNumber" /* Endpoint.SIGN_IN_WITH_PHONE_NUMBER */, _addTidIfNecessary(auth, apiRequest), VERIFY_PHONE_NUMBER_FOR_EXISTING_ERROR_MAP_)];
  3847. });
  3848. });
  3849. }
  3850. /**
  3851. * @license
  3852. * Copyright 2020 Google LLC
  3853. *
  3854. * Licensed under the Apache License, Version 2.0 (the "License");
  3855. * you may not use this file except in compliance with the License.
  3856. * You may obtain a copy of the License at
  3857. *
  3858. * http://www.apache.org/licenses/LICENSE-2.0
  3859. *
  3860. * Unless required by applicable law or agreed to in writing, software
  3861. * distributed under the License is distributed on an "AS IS" BASIS,
  3862. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3863. * See the License for the specific language governing permissions and
  3864. * limitations under the License.
  3865. */
  3866. /**
  3867. * Represents the credentials returned by {@link PhoneAuthProvider}.
  3868. *
  3869. * @public
  3870. */
  3871. var PhoneAuthCredential = /** @class */ (function (_super) {
  3872. tslib.__extends(PhoneAuthCredential, _super);
  3873. function PhoneAuthCredential(params) {
  3874. var _this = _super.call(this, "phone" /* ProviderId.PHONE */, "phone" /* SignInMethod.PHONE */) || this;
  3875. _this.params = params;
  3876. return _this;
  3877. }
  3878. /** @internal */
  3879. PhoneAuthCredential._fromVerification = function (verificationId, verificationCode) {
  3880. return new PhoneAuthCredential({ verificationId: verificationId, verificationCode: verificationCode });
  3881. };
  3882. /** @internal */
  3883. PhoneAuthCredential._fromTokenResponse = function (phoneNumber, temporaryProof) {
  3884. return new PhoneAuthCredential({ phoneNumber: phoneNumber, temporaryProof: temporaryProof });
  3885. };
  3886. /** @internal */
  3887. PhoneAuthCredential.prototype._getIdTokenResponse = function (auth) {
  3888. return signInWithPhoneNumber$1(auth, this._makeVerificationRequest());
  3889. };
  3890. /** @internal */
  3891. PhoneAuthCredential.prototype._linkToIdToken = function (auth, idToken) {
  3892. return linkWithPhoneNumber$1(auth, tslib.__assign({ idToken: idToken }, this._makeVerificationRequest()));
  3893. };
  3894. /** @internal */
  3895. PhoneAuthCredential.prototype._getReauthenticationResolver = function (auth) {
  3896. return verifyPhoneNumberForExisting(auth, this._makeVerificationRequest());
  3897. };
  3898. /** @internal */
  3899. PhoneAuthCredential.prototype._makeVerificationRequest = function () {
  3900. var _a = this.params, temporaryProof = _a.temporaryProof, phoneNumber = _a.phoneNumber, verificationId = _a.verificationId, verificationCode = _a.verificationCode;
  3901. if (temporaryProof && phoneNumber) {
  3902. return { temporaryProof: temporaryProof, phoneNumber: phoneNumber };
  3903. }
  3904. return {
  3905. sessionInfo: verificationId,
  3906. code: verificationCode
  3907. };
  3908. };
  3909. /** {@inheritdoc AuthCredential.toJSON} */
  3910. PhoneAuthCredential.prototype.toJSON = function () {
  3911. var obj = {
  3912. providerId: this.providerId
  3913. };
  3914. if (this.params.phoneNumber) {
  3915. obj.phoneNumber = this.params.phoneNumber;
  3916. }
  3917. if (this.params.temporaryProof) {
  3918. obj.temporaryProof = this.params.temporaryProof;
  3919. }
  3920. if (this.params.verificationCode) {
  3921. obj.verificationCode = this.params.verificationCode;
  3922. }
  3923. if (this.params.verificationId) {
  3924. obj.verificationId = this.params.verificationId;
  3925. }
  3926. return obj;
  3927. };
  3928. /** Generates a phone credential based on a plain object or a JSON string. */
  3929. PhoneAuthCredential.fromJSON = function (json) {
  3930. if (typeof json === 'string') {
  3931. json = JSON.parse(json);
  3932. }
  3933. var _a = json, verificationId = _a.verificationId, verificationCode = _a.verificationCode, phoneNumber = _a.phoneNumber, temporaryProof = _a.temporaryProof;
  3934. if (!verificationCode &&
  3935. !verificationId &&
  3936. !phoneNumber &&
  3937. !temporaryProof) {
  3938. return null;
  3939. }
  3940. return new PhoneAuthCredential({
  3941. verificationId: verificationId,
  3942. verificationCode: verificationCode,
  3943. phoneNumber: phoneNumber,
  3944. temporaryProof: temporaryProof
  3945. });
  3946. };
  3947. return PhoneAuthCredential;
  3948. }(AuthCredential));
  3949. /**
  3950. * @license
  3951. * Copyright 2020 Google LLC
  3952. *
  3953. * Licensed under the Apache License, Version 2.0 (the "License");
  3954. * you may not use this file except in compliance with the License.
  3955. * You may obtain a copy of the License at
  3956. *
  3957. * http://www.apache.org/licenses/LICENSE-2.0
  3958. *
  3959. * Unless required by applicable law or agreed to in writing, software
  3960. * distributed under the License is distributed on an "AS IS" BASIS,
  3961. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3962. * See the License for the specific language governing permissions and
  3963. * limitations under the License.
  3964. */
  3965. /**
  3966. * Maps the mode string in action code URL to Action Code Info operation.
  3967. *
  3968. * @param mode
  3969. */
  3970. function parseMode(mode) {
  3971. switch (mode) {
  3972. case 'recoverEmail':
  3973. return "RECOVER_EMAIL" /* ActionCodeOperation.RECOVER_EMAIL */;
  3974. case 'resetPassword':
  3975. return "PASSWORD_RESET" /* ActionCodeOperation.PASSWORD_RESET */;
  3976. case 'signIn':
  3977. return "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */;
  3978. case 'verifyEmail':
  3979. return "VERIFY_EMAIL" /* ActionCodeOperation.VERIFY_EMAIL */;
  3980. case 'verifyAndChangeEmail':
  3981. return "VERIFY_AND_CHANGE_EMAIL" /* ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL */;
  3982. case 'revertSecondFactorAddition':
  3983. return "REVERT_SECOND_FACTOR_ADDITION" /* ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION */;
  3984. default:
  3985. return null;
  3986. }
  3987. }
  3988. /**
  3989. * Helper to parse FDL links
  3990. *
  3991. * @param url
  3992. */
  3993. function parseDeepLink(url) {
  3994. var link = util.querystringDecode(util.extractQuerystring(url))['link'];
  3995. // Double link case (automatic redirect).
  3996. var doubleDeepLink = link
  3997. ? util.querystringDecode(util.extractQuerystring(link))['deep_link_id']
  3998. : null;
  3999. // iOS custom scheme links.
  4000. var iOSDeepLink = util.querystringDecode(util.extractQuerystring(url))['deep_link_id'];
  4001. var iOSDoubleDeepLink = iOSDeepLink
  4002. ? util.querystringDecode(util.extractQuerystring(iOSDeepLink))['link']
  4003. : null;
  4004. return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
  4005. }
  4006. /**
  4007. * A utility class to parse email action URLs such as password reset, email verification,
  4008. * email link sign in, etc.
  4009. *
  4010. * @public
  4011. */
  4012. var ActionCodeURL = /** @class */ (function () {
  4013. /**
  4014. * @param actionLink - The link from which to extract the URL.
  4015. * @returns The {@link ActionCodeURL} object, or null if the link is invalid.
  4016. *
  4017. * @internal
  4018. */
  4019. function ActionCodeURL(actionLink) {
  4020. var _a, _b, _c, _d, _e, _f;
  4021. var searchParams = util.querystringDecode(util.extractQuerystring(actionLink));
  4022. var apiKey = (_a = searchParams["apiKey" /* QueryField.API_KEY */]) !== null && _a !== void 0 ? _a : null;
  4023. var code = (_b = searchParams["oobCode" /* QueryField.CODE */]) !== null && _b !== void 0 ? _b : null;
  4024. var operation = parseMode((_c = searchParams["mode" /* QueryField.MODE */]) !== null && _c !== void 0 ? _c : null);
  4025. // Validate API key, code and mode.
  4026. _assert(apiKey && code && operation, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4027. this.apiKey = apiKey;
  4028. this.operation = operation;
  4029. this.code = code;
  4030. this.continueUrl = (_d = searchParams["continueUrl" /* QueryField.CONTINUE_URL */]) !== null && _d !== void 0 ? _d : null;
  4031. this.languageCode = (_e = searchParams["languageCode" /* QueryField.LANGUAGE_CODE */]) !== null && _e !== void 0 ? _e : null;
  4032. this.tenantId = (_f = searchParams["tenantId" /* QueryField.TENANT_ID */]) !== null && _f !== void 0 ? _f : null;
  4033. }
  4034. /**
  4035. * Parses the email action link string and returns an {@link ActionCodeURL} if the link is valid,
  4036. * otherwise returns null.
  4037. *
  4038. * @param link - The email action link string.
  4039. * @returns The {@link ActionCodeURL} object, or null if the link is invalid.
  4040. *
  4041. * @public
  4042. */
  4043. ActionCodeURL.parseLink = function (link) {
  4044. var actionLink = parseDeepLink(link);
  4045. try {
  4046. return new ActionCodeURL(actionLink);
  4047. }
  4048. catch (_a) {
  4049. return null;
  4050. }
  4051. };
  4052. return ActionCodeURL;
  4053. }());
  4054. /**
  4055. * Parses the email action link string and returns an {@link ActionCodeURL} if
  4056. * the link is valid, otherwise returns null.
  4057. *
  4058. * @public
  4059. */
  4060. function parseActionCodeURL(link) {
  4061. return ActionCodeURL.parseLink(link);
  4062. }
  4063. /**
  4064. * @license
  4065. * Copyright 2020 Google LLC
  4066. *
  4067. * Licensed under the Apache License, Version 2.0 (the "License");
  4068. * you may not use this file except in compliance with the License.
  4069. * You may obtain a copy of the License at
  4070. *
  4071. * http://www.apache.org/licenses/LICENSE-2.0
  4072. *
  4073. * Unless required by applicable law or agreed to in writing, software
  4074. * distributed under the License is distributed on an "AS IS" BASIS,
  4075. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4076. * See the License for the specific language governing permissions and
  4077. * limitations under the License.
  4078. */
  4079. /**
  4080. * Provider for generating {@link EmailAuthCredential}.
  4081. *
  4082. * @public
  4083. */
  4084. var EmailAuthProvider = /** @class */ (function () {
  4085. function EmailAuthProvider() {
  4086. /**
  4087. * Always set to {@link ProviderId}.PASSWORD, even for email link.
  4088. */
  4089. this.providerId = EmailAuthProvider.PROVIDER_ID;
  4090. }
  4091. /**
  4092. * Initialize an {@link AuthCredential} using an email and password.
  4093. *
  4094. * @example
  4095. * ```javascript
  4096. * const authCredential = EmailAuthProvider.credential(email, password);
  4097. * const userCredential = await signInWithCredential(auth, authCredential);
  4098. * ```
  4099. *
  4100. * @example
  4101. * ```javascript
  4102. * const userCredential = await signInWithEmailAndPassword(auth, email, password);
  4103. * ```
  4104. *
  4105. * @param email - Email address.
  4106. * @param password - User account password.
  4107. * @returns The auth provider credential.
  4108. */
  4109. EmailAuthProvider.credential = function (email, password) {
  4110. return EmailAuthCredential._fromEmailAndPassword(email, password);
  4111. };
  4112. /**
  4113. * Initialize an {@link AuthCredential} using an email and an email link after a sign in with
  4114. * email link operation.
  4115. *
  4116. * @example
  4117. * ```javascript
  4118. * const authCredential = EmailAuthProvider.credentialWithLink(auth, email, emailLink);
  4119. * const userCredential = await signInWithCredential(auth, authCredential);
  4120. * ```
  4121. *
  4122. * @example
  4123. * ```javascript
  4124. * await sendSignInLinkToEmail(auth, email);
  4125. * // Obtain emailLink from user.
  4126. * const userCredential = await signInWithEmailLink(auth, email, emailLink);
  4127. * ```
  4128. *
  4129. * @param auth - The {@link Auth} instance used to verify the link.
  4130. * @param email - Email address.
  4131. * @param emailLink - Sign-in email link.
  4132. * @returns - The auth provider credential.
  4133. */
  4134. EmailAuthProvider.credentialWithLink = function (email, emailLink) {
  4135. var actionCodeUrl = ActionCodeURL.parseLink(emailLink);
  4136. _assert(actionCodeUrl, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4137. return EmailAuthCredential._fromEmailAndCode(email, actionCodeUrl.code, actionCodeUrl.tenantId);
  4138. };
  4139. /**
  4140. * Always set to {@link ProviderId}.PASSWORD, even for email link.
  4141. */
  4142. EmailAuthProvider.PROVIDER_ID = "password" /* ProviderId.PASSWORD */;
  4143. /**
  4144. * Always set to {@link SignInMethod}.EMAIL_PASSWORD.
  4145. */
  4146. EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD = "password" /* SignInMethod.EMAIL_PASSWORD */;
  4147. /**
  4148. * Always set to {@link SignInMethod}.EMAIL_LINK.
  4149. */
  4150. EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD = "emailLink" /* SignInMethod.EMAIL_LINK */;
  4151. return EmailAuthProvider;
  4152. }());
  4153. /**
  4154. * @license
  4155. * Copyright 2020 Google LLC
  4156. *
  4157. * Licensed under the Apache License, Version 2.0 (the "License");
  4158. * you may not use this file except in compliance with the License.
  4159. * You may obtain a copy of the License at
  4160. *
  4161. * http://www.apache.org/licenses/LICENSE-2.0
  4162. *
  4163. * Unless required by applicable law or agreed to in writing, software
  4164. * distributed under the License is distributed on an "AS IS" BASIS,
  4165. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4166. * See the License for the specific language governing permissions and
  4167. * limitations under the License.
  4168. */
  4169. /**
  4170. * The base class for all Federated providers (OAuth (including OIDC), SAML).
  4171. *
  4172. * This class is not meant to be instantiated directly.
  4173. *
  4174. * @public
  4175. */
  4176. var FederatedAuthProvider = /** @class */ (function () {
  4177. /**
  4178. * Constructor for generic OAuth providers.
  4179. *
  4180. * @param providerId - Provider for which credentials should be generated.
  4181. */
  4182. function FederatedAuthProvider(providerId) {
  4183. this.providerId = providerId;
  4184. /** @internal */
  4185. this.defaultLanguageCode = null;
  4186. /** @internal */
  4187. this.customParameters = {};
  4188. }
  4189. /**
  4190. * Set the language gode.
  4191. *
  4192. * @param languageCode - language code
  4193. */
  4194. FederatedAuthProvider.prototype.setDefaultLanguage = function (languageCode) {
  4195. this.defaultLanguageCode = languageCode;
  4196. };
  4197. /**
  4198. * Sets the OAuth custom parameters to pass in an OAuth request for popup and redirect sign-in
  4199. * operations.
  4200. *
  4201. * @remarks
  4202. * For a detailed list, check the reserved required OAuth 2.0 parameters such as `client_id`,
  4203. * `redirect_uri`, `scope`, `response_type`, and `state` are not allowed and will be ignored.
  4204. *
  4205. * @param customOAuthParameters - The custom OAuth parameters to pass in the OAuth request.
  4206. */
  4207. FederatedAuthProvider.prototype.setCustomParameters = function (customOAuthParameters) {
  4208. this.customParameters = customOAuthParameters;
  4209. return this;
  4210. };
  4211. /**
  4212. * Retrieve the current list of {@link CustomParameters}.
  4213. */
  4214. FederatedAuthProvider.prototype.getCustomParameters = function () {
  4215. return this.customParameters;
  4216. };
  4217. return FederatedAuthProvider;
  4218. }());
  4219. /**
  4220. * @license
  4221. * Copyright 2019 Google LLC
  4222. *
  4223. * Licensed under the Apache License, Version 2.0 (the "License");
  4224. * you may not use this file except in compliance with the License.
  4225. * You may obtain a copy of the License at
  4226. *
  4227. * http://www.apache.org/licenses/LICENSE-2.0
  4228. *
  4229. * Unless required by applicable law or agreed to in writing, software
  4230. * distributed under the License is distributed on an "AS IS" BASIS,
  4231. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4232. * See the License for the specific language governing permissions and
  4233. * limitations under the License.
  4234. */
  4235. /**
  4236. * Common code to all OAuth providers. This is separate from the
  4237. * {@link OAuthProvider} so that child providers (like
  4238. * {@link GoogleAuthProvider}) don't inherit the `credential` instance method.
  4239. * Instead, they rely on a static `credential` method.
  4240. */
  4241. var BaseOAuthProvider = /** @class */ (function (_super) {
  4242. tslib.__extends(BaseOAuthProvider, _super);
  4243. function BaseOAuthProvider() {
  4244. var _this = _super !== null && _super.apply(this, arguments) || this;
  4245. /** @internal */
  4246. _this.scopes = [];
  4247. return _this;
  4248. }
  4249. /**
  4250. * Add an OAuth scope to the credential.
  4251. *
  4252. * @param scope - Provider OAuth scope to add.
  4253. */
  4254. BaseOAuthProvider.prototype.addScope = function (scope) {
  4255. // If not already added, add scope to list.
  4256. if (!this.scopes.includes(scope)) {
  4257. this.scopes.push(scope);
  4258. }
  4259. return this;
  4260. };
  4261. /**
  4262. * Retrieve the current list of OAuth scopes.
  4263. */
  4264. BaseOAuthProvider.prototype.getScopes = function () {
  4265. return tslib.__spreadArray([], this.scopes, true);
  4266. };
  4267. return BaseOAuthProvider;
  4268. }(FederatedAuthProvider));
  4269. /**
  4270. * Provider for generating generic {@link OAuthCredential}.
  4271. *
  4272. * @example
  4273. * ```javascript
  4274. * // Sign in using a redirect.
  4275. * const provider = new OAuthProvider('google.com');
  4276. * // Start a sign in process for an unauthenticated user.
  4277. * provider.addScope('profile');
  4278. * provider.addScope('email');
  4279. * await signInWithRedirect(auth, provider);
  4280. * // This will trigger a full page redirect away from your app
  4281. *
  4282. * // After returning from the redirect when your app initializes you can obtain the result
  4283. * const result = await getRedirectResult(auth);
  4284. * if (result) {
  4285. * // This is the signed-in user
  4286. * const user = result.user;
  4287. * // This gives you a OAuth Access Token for the provider.
  4288. * const credential = provider.credentialFromResult(auth, result);
  4289. * const token = credential.accessToken;
  4290. * }
  4291. * ```
  4292. *
  4293. * @example
  4294. * ```javascript
  4295. * // Sign in using a popup.
  4296. * const provider = new OAuthProvider('google.com');
  4297. * provider.addScope('profile');
  4298. * provider.addScope('email');
  4299. * const result = await signInWithPopup(auth, provider);
  4300. *
  4301. * // The signed-in user info.
  4302. * const user = result.user;
  4303. * // This gives you a OAuth Access Token for the provider.
  4304. * const credential = provider.credentialFromResult(auth, result);
  4305. * const token = credential.accessToken;
  4306. * ```
  4307. * @public
  4308. */
  4309. var OAuthProvider = /** @class */ (function (_super) {
  4310. tslib.__extends(OAuthProvider, _super);
  4311. function OAuthProvider() {
  4312. return _super !== null && _super.apply(this, arguments) || this;
  4313. }
  4314. /**
  4315. * Creates an {@link OAuthCredential} from a JSON string or a plain object.
  4316. * @param json - A plain object or a JSON string
  4317. */
  4318. OAuthProvider.credentialFromJSON = function (json) {
  4319. var obj = typeof json === 'string' ? JSON.parse(json) : json;
  4320. _assert('providerId' in obj && 'signInMethod' in obj, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4321. return OAuthCredential._fromParams(obj);
  4322. };
  4323. /**
  4324. * Creates a {@link OAuthCredential} from a generic OAuth provider's access token or ID token.
  4325. *
  4326. * @remarks
  4327. * The raw nonce is required when an ID token with a nonce field is provided. The SHA-256 hash of
  4328. * the raw nonce must match the nonce field in the ID token.
  4329. *
  4330. * @example
  4331. * ```javascript
  4332. * // `googleUser` from the onsuccess Google Sign In callback.
  4333. * // Initialize a generate OAuth provider with a `google.com` providerId.
  4334. * const provider = new OAuthProvider('google.com');
  4335. * const credential = provider.credential({
  4336. * idToken: googleUser.getAuthResponse().id_token,
  4337. * });
  4338. * const result = await signInWithCredential(credential);
  4339. * ```
  4340. *
  4341. * @param params - Either the options object containing the ID token, access token and raw nonce
  4342. * or the ID token string.
  4343. */
  4344. OAuthProvider.prototype.credential = function (params) {
  4345. return this._credential(tslib.__assign(tslib.__assign({}, params), { nonce: params.rawNonce }));
  4346. };
  4347. /** An internal credential method that accepts more permissive options */
  4348. OAuthProvider.prototype._credential = function (params) {
  4349. _assert(params.idToken || params.accessToken, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4350. // For OAuthCredential, sign in method is same as providerId.
  4351. return OAuthCredential._fromParams(tslib.__assign(tslib.__assign({}, params), { providerId: this.providerId, signInMethod: this.providerId }));
  4352. };
  4353. /**
  4354. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  4355. *
  4356. * @param userCredential - The user credential.
  4357. */
  4358. OAuthProvider.credentialFromResult = function (userCredential) {
  4359. return OAuthProvider.oauthCredentialFromTaggedObject(userCredential);
  4360. };
  4361. /**
  4362. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  4363. * thrown during a sign-in, link, or reauthenticate operation.
  4364. *
  4365. * @param userCredential - The user credential.
  4366. */
  4367. OAuthProvider.credentialFromError = function (error) {
  4368. return OAuthProvider.oauthCredentialFromTaggedObject((error.customData || {}));
  4369. };
  4370. OAuthProvider.oauthCredentialFromTaggedObject = function (_a) {
  4371. var tokenResponse = _a._tokenResponse;
  4372. if (!tokenResponse) {
  4373. return null;
  4374. }
  4375. var _b = tokenResponse, oauthIdToken = _b.oauthIdToken, oauthAccessToken = _b.oauthAccessToken, oauthTokenSecret = _b.oauthTokenSecret, pendingToken = _b.pendingToken, nonce = _b.nonce, providerId = _b.providerId;
  4376. if (!oauthAccessToken &&
  4377. !oauthTokenSecret &&
  4378. !oauthIdToken &&
  4379. !pendingToken) {
  4380. return null;
  4381. }
  4382. if (!providerId) {
  4383. return null;
  4384. }
  4385. try {
  4386. return new OAuthProvider(providerId)._credential({
  4387. idToken: oauthIdToken,
  4388. accessToken: oauthAccessToken,
  4389. nonce: nonce,
  4390. pendingToken: pendingToken
  4391. });
  4392. }
  4393. catch (e) {
  4394. return null;
  4395. }
  4396. };
  4397. return OAuthProvider;
  4398. }(BaseOAuthProvider));
  4399. /**
  4400. * @license
  4401. * Copyright 2020 Google LLC
  4402. *
  4403. * Licensed under the Apache License, Version 2.0 (the "License");
  4404. * you may not use this file except in compliance with the License.
  4405. * You may obtain a copy of the License at
  4406. *
  4407. * http://www.apache.org/licenses/LICENSE-2.0
  4408. *
  4409. * Unless required by applicable law or agreed to in writing, software
  4410. * distributed under the License is distributed on an "AS IS" BASIS,
  4411. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4412. * See the License for the specific language governing permissions and
  4413. * limitations under the License.
  4414. */
  4415. /**
  4416. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.FACEBOOK.
  4417. *
  4418. * @example
  4419. * ```javascript
  4420. * // Sign in using a redirect.
  4421. * const provider = new FacebookAuthProvider();
  4422. * // Start a sign in process for an unauthenticated user.
  4423. * provider.addScope('user_birthday');
  4424. * await signInWithRedirect(auth, provider);
  4425. * // This will trigger a full page redirect away from your app
  4426. *
  4427. * // After returning from the redirect when your app initializes you can obtain the result
  4428. * const result = await getRedirectResult(auth);
  4429. * if (result) {
  4430. * // This is the signed-in user
  4431. * const user = result.user;
  4432. * // This gives you a Facebook Access Token.
  4433. * const credential = FacebookAuthProvider.credentialFromResult(result);
  4434. * const token = credential.accessToken;
  4435. * }
  4436. * ```
  4437. *
  4438. * @example
  4439. * ```javascript
  4440. * // Sign in using a popup.
  4441. * const provider = new FacebookAuthProvider();
  4442. * provider.addScope('user_birthday');
  4443. * const result = await signInWithPopup(auth, provider);
  4444. *
  4445. * // The signed-in user info.
  4446. * const user = result.user;
  4447. * // This gives you a Facebook Access Token.
  4448. * const credential = FacebookAuthProvider.credentialFromResult(result);
  4449. * const token = credential.accessToken;
  4450. * ```
  4451. *
  4452. * @public
  4453. */
  4454. var FacebookAuthProvider = /** @class */ (function (_super) {
  4455. tslib.__extends(FacebookAuthProvider, _super);
  4456. function FacebookAuthProvider() {
  4457. return _super.call(this, "facebook.com" /* ProviderId.FACEBOOK */) || this;
  4458. }
  4459. /**
  4460. * Creates a credential for Facebook.
  4461. *
  4462. * @example
  4463. * ```javascript
  4464. * // `event` from the Facebook auth.authResponseChange callback.
  4465. * const credential = FacebookAuthProvider.credential(event.authResponse.accessToken);
  4466. * const result = await signInWithCredential(credential);
  4467. * ```
  4468. *
  4469. * @param accessToken - Facebook access token.
  4470. */
  4471. FacebookAuthProvider.credential = function (accessToken) {
  4472. return OAuthCredential._fromParams({
  4473. providerId: FacebookAuthProvider.PROVIDER_ID,
  4474. signInMethod: FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD,
  4475. accessToken: accessToken
  4476. });
  4477. };
  4478. /**
  4479. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  4480. *
  4481. * @param userCredential - The user credential.
  4482. */
  4483. FacebookAuthProvider.credentialFromResult = function (userCredential) {
  4484. return FacebookAuthProvider.credentialFromTaggedObject(userCredential);
  4485. };
  4486. /**
  4487. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  4488. * thrown during a sign-in, link, or reauthenticate operation.
  4489. *
  4490. * @param userCredential - The user credential.
  4491. */
  4492. FacebookAuthProvider.credentialFromError = function (error) {
  4493. return FacebookAuthProvider.credentialFromTaggedObject((error.customData || {}));
  4494. };
  4495. FacebookAuthProvider.credentialFromTaggedObject = function (_a) {
  4496. var tokenResponse = _a._tokenResponse;
  4497. if (!tokenResponse || !('oauthAccessToken' in tokenResponse)) {
  4498. return null;
  4499. }
  4500. if (!tokenResponse.oauthAccessToken) {
  4501. return null;
  4502. }
  4503. try {
  4504. return FacebookAuthProvider.credential(tokenResponse.oauthAccessToken);
  4505. }
  4506. catch (_b) {
  4507. return null;
  4508. }
  4509. };
  4510. /** Always set to {@link SignInMethod}.FACEBOOK. */
  4511. FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD = "facebook.com" /* SignInMethod.FACEBOOK */;
  4512. /** Always set to {@link ProviderId}.FACEBOOK. */
  4513. FacebookAuthProvider.PROVIDER_ID = "facebook.com" /* ProviderId.FACEBOOK */;
  4514. return FacebookAuthProvider;
  4515. }(BaseOAuthProvider));
  4516. /**
  4517. * @license
  4518. * Copyright 2020 Google LLC
  4519. *
  4520. * Licensed under the Apache License, Version 2.0 (the "License");
  4521. * you may not use this file except in compliance with the License.
  4522. * You may obtain a copy of the License at
  4523. *
  4524. * http://www.apache.org/licenses/LICENSE-2.0
  4525. *
  4526. * Unless required by applicable law or agreed to in writing, software
  4527. * distributed under the License is distributed on an "AS IS" BASIS,
  4528. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4529. * See the License for the specific language governing permissions and
  4530. * limitations under the License.
  4531. */
  4532. /**
  4533. * Provider for generating an an {@link OAuthCredential} for {@link ProviderId}.GOOGLE.
  4534. *
  4535. * @example
  4536. * ```javascript
  4537. * // Sign in using a redirect.
  4538. * const provider = new GoogleAuthProvider();
  4539. * // Start a sign in process for an unauthenticated user.
  4540. * provider.addScope('profile');
  4541. * provider.addScope('email');
  4542. * await signInWithRedirect(auth, provider);
  4543. * // This will trigger a full page redirect away from your app
  4544. *
  4545. * // After returning from the redirect when your app initializes you can obtain the result
  4546. * const result = await getRedirectResult(auth);
  4547. * if (result) {
  4548. * // This is the signed-in user
  4549. * const user = result.user;
  4550. * // This gives you a Google Access Token.
  4551. * const credential = GoogleAuthProvider.credentialFromResult(result);
  4552. * const token = credential.accessToken;
  4553. * }
  4554. * ```
  4555. *
  4556. * @example
  4557. * ```javascript
  4558. * // Sign in using a popup.
  4559. * const provider = new GoogleAuthProvider();
  4560. * provider.addScope('profile');
  4561. * provider.addScope('email');
  4562. * const result = await signInWithPopup(auth, provider);
  4563. *
  4564. * // The signed-in user info.
  4565. * const user = result.user;
  4566. * // This gives you a Google Access Token.
  4567. * const credential = GoogleAuthProvider.credentialFromResult(result);
  4568. * const token = credential.accessToken;
  4569. * ```
  4570. *
  4571. * @public
  4572. */
  4573. var GoogleAuthProvider = /** @class */ (function (_super) {
  4574. tslib.__extends(GoogleAuthProvider, _super);
  4575. function GoogleAuthProvider() {
  4576. var _this = _super.call(this, "google.com" /* ProviderId.GOOGLE */) || this;
  4577. _this.addScope('profile');
  4578. return _this;
  4579. }
  4580. /**
  4581. * Creates a credential for Google. At least one of ID token and access token is required.
  4582. *
  4583. * @example
  4584. * ```javascript
  4585. * // \`googleUser\` from the onsuccess Google Sign In callback.
  4586. * const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
  4587. * const result = await signInWithCredential(credential);
  4588. * ```
  4589. *
  4590. * @param idToken - Google ID token.
  4591. * @param accessToken - Google access token.
  4592. */
  4593. GoogleAuthProvider.credential = function (idToken, accessToken) {
  4594. return OAuthCredential._fromParams({
  4595. providerId: GoogleAuthProvider.PROVIDER_ID,
  4596. signInMethod: GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD,
  4597. idToken: idToken,
  4598. accessToken: accessToken
  4599. });
  4600. };
  4601. /**
  4602. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  4603. *
  4604. * @param userCredential - The user credential.
  4605. */
  4606. GoogleAuthProvider.credentialFromResult = function (userCredential) {
  4607. return GoogleAuthProvider.credentialFromTaggedObject(userCredential);
  4608. };
  4609. /**
  4610. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  4611. * thrown during a sign-in, link, or reauthenticate operation.
  4612. *
  4613. * @param userCredential - The user credential.
  4614. */
  4615. GoogleAuthProvider.credentialFromError = function (error) {
  4616. return GoogleAuthProvider.credentialFromTaggedObject((error.customData || {}));
  4617. };
  4618. GoogleAuthProvider.credentialFromTaggedObject = function (_a) {
  4619. var tokenResponse = _a._tokenResponse;
  4620. if (!tokenResponse) {
  4621. return null;
  4622. }
  4623. var _b = tokenResponse, oauthIdToken = _b.oauthIdToken, oauthAccessToken = _b.oauthAccessToken;
  4624. if (!oauthIdToken && !oauthAccessToken) {
  4625. // This could be an oauth 1 credential or a phone credential
  4626. return null;
  4627. }
  4628. try {
  4629. return GoogleAuthProvider.credential(oauthIdToken, oauthAccessToken);
  4630. }
  4631. catch (_c) {
  4632. return null;
  4633. }
  4634. };
  4635. /** Always set to {@link SignInMethod}.GOOGLE. */
  4636. GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD = "google.com" /* SignInMethod.GOOGLE */;
  4637. /** Always set to {@link ProviderId}.GOOGLE. */
  4638. GoogleAuthProvider.PROVIDER_ID = "google.com" /* ProviderId.GOOGLE */;
  4639. return GoogleAuthProvider;
  4640. }(BaseOAuthProvider));
  4641. /**
  4642. * @license
  4643. * Copyright 2020 Google LLC
  4644. *
  4645. * Licensed under the Apache License, Version 2.0 (the "License");
  4646. * you may not use this file except in compliance with the License.
  4647. * You may obtain a copy of the License at
  4648. *
  4649. * http://www.apache.org/licenses/LICENSE-2.0
  4650. *
  4651. * Unless required by applicable law or agreed to in writing, software
  4652. * distributed under the License is distributed on an "AS IS" BASIS,
  4653. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4654. * See the License for the specific language governing permissions and
  4655. * limitations under the License.
  4656. */
  4657. /**
  4658. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.GITHUB.
  4659. *
  4660. * @remarks
  4661. * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect directly, or use
  4662. * the {@link signInWithPopup} handler:
  4663. *
  4664. * @example
  4665. * ```javascript
  4666. * // Sign in using a redirect.
  4667. * const provider = new GithubAuthProvider();
  4668. * // Start a sign in process for an unauthenticated user.
  4669. * provider.addScope('repo');
  4670. * await signInWithRedirect(auth, provider);
  4671. * // This will trigger a full page redirect away from your app
  4672. *
  4673. * // After returning from the redirect when your app initializes you can obtain the result
  4674. * const result = await getRedirectResult(auth);
  4675. * if (result) {
  4676. * // This is the signed-in user
  4677. * const user = result.user;
  4678. * // This gives you a Github Access Token.
  4679. * const credential = GithubAuthProvider.credentialFromResult(result);
  4680. * const token = credential.accessToken;
  4681. * }
  4682. * ```
  4683. *
  4684. * @example
  4685. * ```javascript
  4686. * // Sign in using a popup.
  4687. * const provider = new GithubAuthProvider();
  4688. * provider.addScope('repo');
  4689. * const result = await signInWithPopup(auth, provider);
  4690. *
  4691. * // The signed-in user info.
  4692. * const user = result.user;
  4693. * // This gives you a Github Access Token.
  4694. * const credential = GithubAuthProvider.credentialFromResult(result);
  4695. * const token = credential.accessToken;
  4696. * ```
  4697. * @public
  4698. */
  4699. var GithubAuthProvider = /** @class */ (function (_super) {
  4700. tslib.__extends(GithubAuthProvider, _super);
  4701. function GithubAuthProvider() {
  4702. return _super.call(this, "github.com" /* ProviderId.GITHUB */) || this;
  4703. }
  4704. /**
  4705. * Creates a credential for Github.
  4706. *
  4707. * @param accessToken - Github access token.
  4708. */
  4709. GithubAuthProvider.credential = function (accessToken) {
  4710. return OAuthCredential._fromParams({
  4711. providerId: GithubAuthProvider.PROVIDER_ID,
  4712. signInMethod: GithubAuthProvider.GITHUB_SIGN_IN_METHOD,
  4713. accessToken: accessToken
  4714. });
  4715. };
  4716. /**
  4717. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  4718. *
  4719. * @param userCredential - The user credential.
  4720. */
  4721. GithubAuthProvider.credentialFromResult = function (userCredential) {
  4722. return GithubAuthProvider.credentialFromTaggedObject(userCredential);
  4723. };
  4724. /**
  4725. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  4726. * thrown during a sign-in, link, or reauthenticate operation.
  4727. *
  4728. * @param userCredential - The user credential.
  4729. */
  4730. GithubAuthProvider.credentialFromError = function (error) {
  4731. return GithubAuthProvider.credentialFromTaggedObject((error.customData || {}));
  4732. };
  4733. GithubAuthProvider.credentialFromTaggedObject = function (_a) {
  4734. var tokenResponse = _a._tokenResponse;
  4735. if (!tokenResponse || !('oauthAccessToken' in tokenResponse)) {
  4736. return null;
  4737. }
  4738. if (!tokenResponse.oauthAccessToken) {
  4739. return null;
  4740. }
  4741. try {
  4742. return GithubAuthProvider.credential(tokenResponse.oauthAccessToken);
  4743. }
  4744. catch (_b) {
  4745. return null;
  4746. }
  4747. };
  4748. /** Always set to {@link SignInMethod}.GITHUB. */
  4749. GithubAuthProvider.GITHUB_SIGN_IN_METHOD = "github.com" /* SignInMethod.GITHUB */;
  4750. /** Always set to {@link ProviderId}.GITHUB. */
  4751. GithubAuthProvider.PROVIDER_ID = "github.com" /* ProviderId.GITHUB */;
  4752. return GithubAuthProvider;
  4753. }(BaseOAuthProvider));
  4754. /**
  4755. * @license
  4756. * Copyright 2020 Google LLC
  4757. *
  4758. * Licensed under the Apache License, Version 2.0 (the "License");
  4759. * you may not use this file except in compliance with the License.
  4760. * You may obtain a copy of the License at
  4761. *
  4762. * http://www.apache.org/licenses/LICENSE-2.0
  4763. *
  4764. * Unless required by applicable law or agreed to in writing, software
  4765. * distributed under the License is distributed on an "AS IS" BASIS,
  4766. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4767. * See the License for the specific language governing permissions and
  4768. * limitations under the License.
  4769. */
  4770. var IDP_REQUEST_URI = 'http://localhost';
  4771. /**
  4772. * @public
  4773. */
  4774. var SAMLAuthCredential = /** @class */ (function (_super) {
  4775. tslib.__extends(SAMLAuthCredential, _super);
  4776. /** @internal */
  4777. function SAMLAuthCredential(providerId, pendingToken) {
  4778. var _this = _super.call(this, providerId, providerId) || this;
  4779. _this.pendingToken = pendingToken;
  4780. return _this;
  4781. }
  4782. /** @internal */
  4783. SAMLAuthCredential.prototype._getIdTokenResponse = function (auth) {
  4784. var request = this.buildRequest();
  4785. return signInWithIdp(auth, request);
  4786. };
  4787. /** @internal */
  4788. SAMLAuthCredential.prototype._linkToIdToken = function (auth, idToken) {
  4789. var request = this.buildRequest();
  4790. request.idToken = idToken;
  4791. return signInWithIdp(auth, request);
  4792. };
  4793. /** @internal */
  4794. SAMLAuthCredential.prototype._getReauthenticationResolver = function (auth) {
  4795. var request = this.buildRequest();
  4796. request.autoCreate = false;
  4797. return signInWithIdp(auth, request);
  4798. };
  4799. /** {@inheritdoc AuthCredential.toJSON} */
  4800. SAMLAuthCredential.prototype.toJSON = function () {
  4801. return {
  4802. signInMethod: this.signInMethod,
  4803. providerId: this.providerId,
  4804. pendingToken: this.pendingToken
  4805. };
  4806. };
  4807. /**
  4808. * Static method to deserialize a JSON representation of an object into an
  4809. * {@link AuthCredential}.
  4810. *
  4811. * @param json - Input can be either Object or the stringified representation of the object.
  4812. * When string is provided, JSON.parse would be called first.
  4813. *
  4814. * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
  4815. */
  4816. SAMLAuthCredential.fromJSON = function (json) {
  4817. var obj = typeof json === 'string' ? JSON.parse(json) : json;
  4818. var providerId = obj.providerId, signInMethod = obj.signInMethod, pendingToken = obj.pendingToken;
  4819. if (!providerId ||
  4820. !signInMethod ||
  4821. !pendingToken ||
  4822. providerId !== signInMethod) {
  4823. return null;
  4824. }
  4825. return new SAMLAuthCredential(providerId, pendingToken);
  4826. };
  4827. /**
  4828. * Helper static method to avoid exposing the constructor to end users.
  4829. *
  4830. * @internal
  4831. */
  4832. SAMLAuthCredential._create = function (providerId, pendingToken) {
  4833. return new SAMLAuthCredential(providerId, pendingToken);
  4834. };
  4835. SAMLAuthCredential.prototype.buildRequest = function () {
  4836. return {
  4837. requestUri: IDP_REQUEST_URI,
  4838. returnSecureToken: true,
  4839. pendingToken: this.pendingToken
  4840. };
  4841. };
  4842. return SAMLAuthCredential;
  4843. }(AuthCredential));
  4844. /**
  4845. * @license
  4846. * Copyright 2020 Google LLC
  4847. *
  4848. * Licensed under the Apache License, Version 2.0 (the "License");
  4849. * you may not use this file except in compliance with the License.
  4850. * You may obtain a copy of the License at
  4851. *
  4852. * http://www.apache.org/licenses/LICENSE-2.0
  4853. *
  4854. * Unless required by applicable law or agreed to in writing, software
  4855. * distributed under the License is distributed on an "AS IS" BASIS,
  4856. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4857. * See the License for the specific language governing permissions and
  4858. * limitations under the License.
  4859. */
  4860. var SAML_PROVIDER_PREFIX = 'saml.';
  4861. /**
  4862. * An {@link AuthProvider} for SAML.
  4863. *
  4864. * @public
  4865. */
  4866. var SAMLAuthProvider = /** @class */ (function (_super) {
  4867. tslib.__extends(SAMLAuthProvider, _super);
  4868. /**
  4869. * Constructor. The providerId must start with "saml."
  4870. * @param providerId - SAML provider ID.
  4871. */
  4872. function SAMLAuthProvider(providerId) {
  4873. _assert(providerId.startsWith(SAML_PROVIDER_PREFIX), "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4874. return _super.call(this, providerId) || this;
  4875. }
  4876. /**
  4877. * Generates an {@link AuthCredential} from a {@link UserCredential} after a
  4878. * successful SAML flow completes.
  4879. *
  4880. * @remarks
  4881. *
  4882. * For example, to get an {@link AuthCredential}, you could write the
  4883. * following code:
  4884. *
  4885. * ```js
  4886. * const userCredential = await signInWithPopup(auth, samlProvider);
  4887. * const credential = SAMLAuthProvider.credentialFromResult(userCredential);
  4888. * ```
  4889. *
  4890. * @param userCredential - The user credential.
  4891. */
  4892. SAMLAuthProvider.credentialFromResult = function (userCredential) {
  4893. return SAMLAuthProvider.samlCredentialFromTaggedObject(userCredential);
  4894. };
  4895. /**
  4896. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  4897. * thrown during a sign-in, link, or reauthenticate operation.
  4898. *
  4899. * @param userCredential - The user credential.
  4900. */
  4901. SAMLAuthProvider.credentialFromError = function (error) {
  4902. return SAMLAuthProvider.samlCredentialFromTaggedObject((error.customData || {}));
  4903. };
  4904. /**
  4905. * Creates an {@link AuthCredential} from a JSON string or a plain object.
  4906. * @param json - A plain object or a JSON string
  4907. */
  4908. SAMLAuthProvider.credentialFromJSON = function (json) {
  4909. var credential = SAMLAuthCredential.fromJSON(json);
  4910. _assert(credential, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  4911. return credential;
  4912. };
  4913. SAMLAuthProvider.samlCredentialFromTaggedObject = function (_a) {
  4914. var tokenResponse = _a._tokenResponse;
  4915. if (!tokenResponse) {
  4916. return null;
  4917. }
  4918. var _b = tokenResponse, pendingToken = _b.pendingToken, providerId = _b.providerId;
  4919. if (!pendingToken || !providerId) {
  4920. return null;
  4921. }
  4922. try {
  4923. return SAMLAuthCredential._create(providerId, pendingToken);
  4924. }
  4925. catch (e) {
  4926. return null;
  4927. }
  4928. };
  4929. return SAMLAuthProvider;
  4930. }(FederatedAuthProvider));
  4931. /**
  4932. * @license
  4933. * Copyright 2020 Google LLC
  4934. *
  4935. * Licensed under the Apache License, Version 2.0 (the "License");
  4936. * you may not use this file except in compliance with the License.
  4937. * You may obtain a copy of the License at
  4938. *
  4939. * http://www.apache.org/licenses/LICENSE-2.0
  4940. *
  4941. * Unless required by applicable law or agreed to in writing, software
  4942. * distributed under the License is distributed on an "AS IS" BASIS,
  4943. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4944. * See the License for the specific language governing permissions and
  4945. * limitations under the License.
  4946. */
  4947. /**
  4948. * Provider for generating an {@link OAuthCredential} for {@link ProviderId}.TWITTER.
  4949. *
  4950. * @example
  4951. * ```javascript
  4952. * // Sign in using a redirect.
  4953. * const provider = new TwitterAuthProvider();
  4954. * // Start a sign in process for an unauthenticated user.
  4955. * await signInWithRedirect(auth, provider);
  4956. * // This will trigger a full page redirect away from your app
  4957. *
  4958. * // After returning from the redirect when your app initializes you can obtain the result
  4959. * const result = await getRedirectResult(auth);
  4960. * if (result) {
  4961. * // This is the signed-in user
  4962. * const user = result.user;
  4963. * // This gives you a Twitter Access Token and Secret.
  4964. * const credential = TwitterAuthProvider.credentialFromResult(result);
  4965. * const token = credential.accessToken;
  4966. * const secret = credential.secret;
  4967. * }
  4968. * ```
  4969. *
  4970. * @example
  4971. * ```javascript
  4972. * // Sign in using a popup.
  4973. * const provider = new TwitterAuthProvider();
  4974. * const result = await signInWithPopup(auth, provider);
  4975. *
  4976. * // The signed-in user info.
  4977. * const user = result.user;
  4978. * // This gives you a Twitter Access Token and Secret.
  4979. * const credential = TwitterAuthProvider.credentialFromResult(result);
  4980. * const token = credential.accessToken;
  4981. * const secret = credential.secret;
  4982. * ```
  4983. *
  4984. * @public
  4985. */
  4986. var TwitterAuthProvider = /** @class */ (function (_super) {
  4987. tslib.__extends(TwitterAuthProvider, _super);
  4988. function TwitterAuthProvider() {
  4989. return _super.call(this, "twitter.com" /* ProviderId.TWITTER */) || this;
  4990. }
  4991. /**
  4992. * Creates a credential for Twitter.
  4993. *
  4994. * @param token - Twitter access token.
  4995. * @param secret - Twitter secret.
  4996. */
  4997. TwitterAuthProvider.credential = function (token, secret) {
  4998. return OAuthCredential._fromParams({
  4999. providerId: TwitterAuthProvider.PROVIDER_ID,
  5000. signInMethod: TwitterAuthProvider.TWITTER_SIGN_IN_METHOD,
  5001. oauthToken: token,
  5002. oauthTokenSecret: secret
  5003. });
  5004. };
  5005. /**
  5006. * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}.
  5007. *
  5008. * @param userCredential - The user credential.
  5009. */
  5010. TwitterAuthProvider.credentialFromResult = function (userCredential) {
  5011. return TwitterAuthProvider.credentialFromTaggedObject(userCredential);
  5012. };
  5013. /**
  5014. * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
  5015. * thrown during a sign-in, link, or reauthenticate operation.
  5016. *
  5017. * @param userCredential - The user credential.
  5018. */
  5019. TwitterAuthProvider.credentialFromError = function (error) {
  5020. return TwitterAuthProvider.credentialFromTaggedObject((error.customData || {}));
  5021. };
  5022. TwitterAuthProvider.credentialFromTaggedObject = function (_a) {
  5023. var tokenResponse = _a._tokenResponse;
  5024. if (!tokenResponse) {
  5025. return null;
  5026. }
  5027. var _b = tokenResponse, oauthAccessToken = _b.oauthAccessToken, oauthTokenSecret = _b.oauthTokenSecret;
  5028. if (!oauthAccessToken || !oauthTokenSecret) {
  5029. return null;
  5030. }
  5031. try {
  5032. return TwitterAuthProvider.credential(oauthAccessToken, oauthTokenSecret);
  5033. }
  5034. catch (_c) {
  5035. return null;
  5036. }
  5037. };
  5038. /** Always set to {@link SignInMethod}.TWITTER. */
  5039. TwitterAuthProvider.TWITTER_SIGN_IN_METHOD = "twitter.com" /* SignInMethod.TWITTER */;
  5040. /** Always set to {@link ProviderId}.TWITTER. */
  5041. TwitterAuthProvider.PROVIDER_ID = "twitter.com" /* ProviderId.TWITTER */;
  5042. return TwitterAuthProvider;
  5043. }(BaseOAuthProvider));
  5044. /**
  5045. * @license
  5046. * Copyright 2020 Google LLC
  5047. *
  5048. * Licensed under the Apache License, Version 2.0 (the "License");
  5049. * you may not use this file except in compliance with the License.
  5050. * You may obtain a copy of the License at
  5051. *
  5052. * http://www.apache.org/licenses/LICENSE-2.0
  5053. *
  5054. * Unless required by applicable law or agreed to in writing, software
  5055. * distributed under the License is distributed on an "AS IS" BASIS,
  5056. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5057. * See the License for the specific language governing permissions and
  5058. * limitations under the License.
  5059. */
  5060. function signUp(auth, request) {
  5061. return tslib.__awaiter(this, void 0, void 0, function () {
  5062. return tslib.__generator(this, function (_a) {
  5063. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signUp" /* Endpoint.SIGN_UP */, _addTidIfNecessary(auth, request))];
  5064. });
  5065. });
  5066. }
  5067. /**
  5068. * @license
  5069. * Copyright 2020 Google LLC
  5070. *
  5071. * Licensed under the Apache License, Version 2.0 (the "License");
  5072. * you may not use this file except in compliance with the License.
  5073. * You may obtain a copy of the License at
  5074. *
  5075. * http://www.apache.org/licenses/LICENSE-2.0
  5076. *
  5077. * Unless required by applicable law or agreed to in writing, software
  5078. * distributed under the License is distributed on an "AS IS" BASIS,
  5079. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5080. * See the License for the specific language governing permissions and
  5081. * limitations under the License.
  5082. */
  5083. var UserCredentialImpl = /** @class */ (function () {
  5084. function UserCredentialImpl(params) {
  5085. this.user = params.user;
  5086. this.providerId = params.providerId;
  5087. this._tokenResponse = params._tokenResponse;
  5088. this.operationType = params.operationType;
  5089. }
  5090. UserCredentialImpl._fromIdTokenResponse = function (auth, operationType, idTokenResponse, isAnonymous) {
  5091. if (isAnonymous === void 0) { isAnonymous = false; }
  5092. return tslib.__awaiter(this, void 0, void 0, function () {
  5093. var user, providerId, userCred;
  5094. return tslib.__generator(this, function (_a) {
  5095. switch (_a.label) {
  5096. case 0: return [4 /*yield*/, UserImpl._fromIdTokenResponse(auth, idTokenResponse, isAnonymous)];
  5097. case 1:
  5098. user = _a.sent();
  5099. providerId = providerIdForResponse(idTokenResponse);
  5100. userCred = new UserCredentialImpl({
  5101. user: user,
  5102. providerId: providerId,
  5103. _tokenResponse: idTokenResponse,
  5104. operationType: operationType
  5105. });
  5106. return [2 /*return*/, userCred];
  5107. }
  5108. });
  5109. });
  5110. };
  5111. UserCredentialImpl._forOperation = function (user, operationType, response) {
  5112. return tslib.__awaiter(this, void 0, void 0, function () {
  5113. var providerId;
  5114. return tslib.__generator(this, function (_a) {
  5115. switch (_a.label) {
  5116. case 0: return [4 /*yield*/, user._updateTokensIfNecessary(response, /* reload */ true)];
  5117. case 1:
  5118. _a.sent();
  5119. providerId = providerIdForResponse(response);
  5120. return [2 /*return*/, new UserCredentialImpl({
  5121. user: user,
  5122. providerId: providerId,
  5123. _tokenResponse: response,
  5124. operationType: operationType
  5125. })];
  5126. }
  5127. });
  5128. });
  5129. };
  5130. return UserCredentialImpl;
  5131. }());
  5132. function providerIdForResponse(response) {
  5133. if (response.providerId) {
  5134. return response.providerId;
  5135. }
  5136. if ('phoneNumber' in response) {
  5137. return "phone" /* ProviderId.PHONE */;
  5138. }
  5139. return null;
  5140. }
  5141. /**
  5142. * @license
  5143. * Copyright 2020 Google LLC
  5144. *
  5145. * Licensed under the Apache License, Version 2.0 (the "License");
  5146. * you may not use this file except in compliance with the License.
  5147. * You may obtain a copy of the License at
  5148. *
  5149. * http://www.apache.org/licenses/LICENSE-2.0
  5150. *
  5151. * Unless required by applicable law or agreed to in writing, software
  5152. * distributed under the License is distributed on an "AS IS" BASIS,
  5153. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5154. * See the License for the specific language governing permissions and
  5155. * limitations under the License.
  5156. */
  5157. /**
  5158. * Asynchronously signs in as an anonymous user.
  5159. *
  5160. * @remarks
  5161. * If there is already an anonymous user signed in, that user will be returned; otherwise, a
  5162. * new anonymous user identity will be created and returned.
  5163. *
  5164. * @param auth - The {@link Auth} instance.
  5165. *
  5166. * @public
  5167. */
  5168. function signInAnonymously(auth) {
  5169. var _a;
  5170. return tslib.__awaiter(this, void 0, void 0, function () {
  5171. var authInternal, response, userCredential;
  5172. return tslib.__generator(this, function (_b) {
  5173. switch (_b.label) {
  5174. case 0:
  5175. authInternal = _castAuth(auth);
  5176. return [4 /*yield*/, authInternal._initializationPromise];
  5177. case 1:
  5178. _b.sent();
  5179. if ((_a = authInternal.currentUser) === null || _a === void 0 ? void 0 : _a.isAnonymous) {
  5180. // If an anonymous user is already signed in, no need to sign them in again.
  5181. return [2 /*return*/, new UserCredentialImpl({
  5182. user: authInternal.currentUser,
  5183. providerId: null,
  5184. operationType: "signIn" /* OperationType.SIGN_IN */
  5185. })];
  5186. }
  5187. return [4 /*yield*/, signUp(authInternal, {
  5188. returnSecureToken: true
  5189. })];
  5190. case 2:
  5191. response = _b.sent();
  5192. return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response, true)];
  5193. case 3:
  5194. userCredential = _b.sent();
  5195. return [4 /*yield*/, authInternal._updateCurrentUser(userCredential.user)];
  5196. case 4:
  5197. _b.sent();
  5198. return [2 /*return*/, userCredential];
  5199. }
  5200. });
  5201. });
  5202. }
  5203. /**
  5204. * @license
  5205. * Copyright 2020 Google LLC
  5206. *
  5207. * Licensed under the Apache License, Version 2.0 (the "License");
  5208. * you may not use this file except in compliance with the License.
  5209. * You may obtain a copy of the License at
  5210. *
  5211. * http://www.apache.org/licenses/LICENSE-2.0
  5212. *
  5213. * Unless required by applicable law or agreed to in writing, software
  5214. * distributed under the License is distributed on an "AS IS" BASIS,
  5215. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5216. * See the License for the specific language governing permissions and
  5217. * limitations under the License.
  5218. */
  5219. var MultiFactorError = /** @class */ (function (_super) {
  5220. tslib.__extends(MultiFactorError, _super);
  5221. function MultiFactorError(auth, error, operationType, user) {
  5222. var _this = this;
  5223. var _a;
  5224. _this = _super.call(this, error.code, error.message) || this;
  5225. _this.operationType = operationType;
  5226. _this.user = user;
  5227. // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
  5228. Object.setPrototypeOf(_this, MultiFactorError.prototype);
  5229. _this.customData = {
  5230. appName: auth.name,
  5231. tenantId: (_a = auth.tenantId) !== null && _a !== void 0 ? _a : undefined,
  5232. _serverResponse: error.customData._serverResponse,
  5233. operationType: operationType
  5234. };
  5235. return _this;
  5236. }
  5237. MultiFactorError._fromErrorAndOperation = function (auth, error, operationType, user) {
  5238. return new MultiFactorError(auth, error, operationType, user);
  5239. };
  5240. return MultiFactorError;
  5241. }(util.FirebaseError));
  5242. function _processCredentialSavingMfaContextIfNecessary(auth, operationType, credential, user) {
  5243. var idTokenProvider = operationType === "reauthenticate" /* OperationType.REAUTHENTICATE */
  5244. ? credential._getReauthenticationResolver(auth)
  5245. : credential._getIdTokenResponse(auth);
  5246. return idTokenProvider.catch(function (error) {
  5247. if (error.code === "auth/".concat("multi-factor-auth-required" /* AuthErrorCode.MFA_REQUIRED */)) {
  5248. throw MultiFactorError._fromErrorAndOperation(auth, error, operationType, user);
  5249. }
  5250. throw error;
  5251. });
  5252. }
  5253. /**
  5254. * @license
  5255. * Copyright 2020 Google LLC
  5256. *
  5257. * Licensed under the Apache License, Version 2.0 (the "License");
  5258. * you may not use this file except in compliance with the License.
  5259. * You may obtain a copy of the License at
  5260. *
  5261. * http://www.apache.org/licenses/LICENSE-2.0
  5262. *
  5263. * Unless required by applicable law or agreed to in writing, software
  5264. * distributed under the License is distributed on an "AS IS" BASIS,
  5265. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5266. * See the License for the specific language governing permissions and
  5267. * limitations under the License.
  5268. */
  5269. /**
  5270. * Takes a set of UserInfo provider data and converts it to a set of names
  5271. */
  5272. function providerDataAsNames(providerData) {
  5273. return new Set(providerData
  5274. .map(function (_a) {
  5275. var providerId = _a.providerId;
  5276. return providerId;
  5277. })
  5278. .filter(function (pid) { return !!pid; }));
  5279. }
  5280. /**
  5281. * @license
  5282. * Copyright 2019 Google LLC
  5283. *
  5284. * Licensed under the Apache License, Version 2.0 (the "License");
  5285. * you may not use this file except in compliance with the License.
  5286. * You may obtain a copy of the License at
  5287. *
  5288. * http://www.apache.org/licenses/LICENSE-2.0
  5289. *
  5290. * Unless required by applicable law or agreed to in writing, software
  5291. * distributed under the License is distributed on an "AS IS" BASIS,
  5292. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5293. * See the License for the specific language governing permissions and
  5294. * limitations under the License.
  5295. */
  5296. /**
  5297. * Unlinks a provider from a user account.
  5298. *
  5299. * @param user - The user.
  5300. * @param providerId - The provider to unlink.
  5301. *
  5302. * @public
  5303. */
  5304. function unlink(user, providerId) {
  5305. return tslib.__awaiter(this, void 0, void 0, function () {
  5306. var userInternal, providerUserInfo, _a, _b, providersLeft;
  5307. var _c;
  5308. return tslib.__generator(this, function (_d) {
  5309. switch (_d.label) {
  5310. case 0:
  5311. userInternal = util.getModularInstance(user);
  5312. return [4 /*yield*/, _assertLinkedStatus(true, userInternal, providerId)];
  5313. case 1:
  5314. _d.sent();
  5315. _a = deleteLinkedAccounts;
  5316. _b = [userInternal.auth];
  5317. _c = {};
  5318. return [4 /*yield*/, userInternal.getIdToken()];
  5319. case 2: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.idToken = _d.sent(),
  5320. _c.deleteProvider = [providerId],
  5321. _c)]))];
  5322. case 3:
  5323. providerUserInfo = (_d.sent()).providerUserInfo;
  5324. providersLeft = providerDataAsNames(providerUserInfo || []);
  5325. userInternal.providerData = userInternal.providerData.filter(function (pd) {
  5326. return providersLeft.has(pd.providerId);
  5327. });
  5328. if (!providersLeft.has("phone" /* ProviderId.PHONE */)) {
  5329. userInternal.phoneNumber = null;
  5330. }
  5331. return [4 /*yield*/, userInternal.auth._persistUserIfCurrent(userInternal)];
  5332. case 4:
  5333. _d.sent();
  5334. return [2 /*return*/, userInternal];
  5335. }
  5336. });
  5337. });
  5338. }
  5339. function _link(user, credential, bypassAuthState) {
  5340. if (bypassAuthState === void 0) { bypassAuthState = false; }
  5341. return tslib.__awaiter(this, void 0, void 0, function () {
  5342. var response, _a, _b, _c, _d, _e;
  5343. return tslib.__generator(this, function (_f) {
  5344. switch (_f.label) {
  5345. case 0:
  5346. _a = _logoutIfInvalidated;
  5347. _b = [user];
  5348. _d = (_c = credential)._linkToIdToken;
  5349. _e = [user.auth];
  5350. return [4 /*yield*/, user.getIdToken()];
  5351. case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([_d.apply(_c, _e.concat([_f.sent()])),
  5352. bypassAuthState]))];
  5353. case 2:
  5354. response = _f.sent();
  5355. return [2 /*return*/, UserCredentialImpl._forOperation(user, "link" /* OperationType.LINK */, response)];
  5356. }
  5357. });
  5358. });
  5359. }
  5360. function _assertLinkedStatus(expected, user, provider) {
  5361. return tslib.__awaiter(this, void 0, void 0, function () {
  5362. var providerIds, code;
  5363. return tslib.__generator(this, function (_a) {
  5364. switch (_a.label) {
  5365. case 0: return [4 /*yield*/, _reloadWithoutSaving(user)];
  5366. case 1:
  5367. _a.sent();
  5368. providerIds = providerDataAsNames(user.providerData);
  5369. code = expected === false
  5370. ? "provider-already-linked" /* AuthErrorCode.PROVIDER_ALREADY_LINKED */
  5371. : "no-such-provider" /* AuthErrorCode.NO_SUCH_PROVIDER */;
  5372. _assert(providerIds.has(provider) === expected, user.auth, code);
  5373. return [2 /*return*/];
  5374. }
  5375. });
  5376. });
  5377. }
  5378. /**
  5379. * @license
  5380. * Copyright 2019 Google LLC
  5381. *
  5382. * Licensed under the Apache License, Version 2.0 (the "License");
  5383. * you may not use this file except in compliance with the License.
  5384. * You may obtain a copy of the License at
  5385. *
  5386. * http://www.apache.org/licenses/LICENSE-2.0
  5387. *
  5388. * Unless required by applicable law or agreed to in writing, software
  5389. * distributed under the License is distributed on an "AS IS" BASIS,
  5390. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5391. * See the License for the specific language governing permissions and
  5392. * limitations under the License.
  5393. */
  5394. function _reauthenticate(user, credential, bypassAuthState) {
  5395. if (bypassAuthState === void 0) { bypassAuthState = false; }
  5396. return tslib.__awaiter(this, void 0, void 0, function () {
  5397. var auth, operationType, response, parsed, localId, e_1;
  5398. return tslib.__generator(this, function (_a) {
  5399. switch (_a.label) {
  5400. case 0:
  5401. auth = user.auth;
  5402. operationType = "reauthenticate" /* OperationType.REAUTHENTICATE */;
  5403. _a.label = 1;
  5404. case 1:
  5405. _a.trys.push([1, 3, , 4]);
  5406. return [4 /*yield*/, _logoutIfInvalidated(user, _processCredentialSavingMfaContextIfNecessary(auth, operationType, credential, user), bypassAuthState)];
  5407. case 2:
  5408. response = _a.sent();
  5409. _assert(response.idToken, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5410. parsed = _parseToken(response.idToken);
  5411. _assert(parsed, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5412. localId = parsed.sub;
  5413. _assert(user.uid === localId, auth, "user-mismatch" /* AuthErrorCode.USER_MISMATCH */);
  5414. return [2 /*return*/, UserCredentialImpl._forOperation(user, operationType, response)];
  5415. case 3:
  5416. e_1 = _a.sent();
  5417. // Convert user deleted error into user mismatch
  5418. if ((e_1 === null || e_1 === void 0 ? void 0 : e_1.code) === "auth/".concat("user-not-found" /* AuthErrorCode.USER_DELETED */)) {
  5419. _fail(auth, "user-mismatch" /* AuthErrorCode.USER_MISMATCH */);
  5420. }
  5421. throw e_1;
  5422. case 4: return [2 /*return*/];
  5423. }
  5424. });
  5425. });
  5426. }
  5427. /**
  5428. * @license
  5429. * Copyright 2020 Google LLC
  5430. *
  5431. * Licensed under the Apache License, Version 2.0 (the "License");
  5432. * you may not use this file except in compliance with the License.
  5433. * You may obtain a copy of the License at
  5434. *
  5435. * http://www.apache.org/licenses/LICENSE-2.0
  5436. *
  5437. * Unless required by applicable law or agreed to in writing, software
  5438. * distributed under the License is distributed on an "AS IS" BASIS,
  5439. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5440. * See the License for the specific language governing permissions and
  5441. * limitations under the License.
  5442. */
  5443. function _signInWithCredential(auth, credential, bypassAuthState) {
  5444. if (bypassAuthState === void 0) { bypassAuthState = false; }
  5445. return tslib.__awaiter(this, void 0, void 0, function () {
  5446. var operationType, response, userCredential;
  5447. return tslib.__generator(this, function (_a) {
  5448. switch (_a.label) {
  5449. case 0:
  5450. operationType = "signIn" /* OperationType.SIGN_IN */;
  5451. return [4 /*yield*/, _processCredentialSavingMfaContextIfNecessary(auth, operationType, credential)];
  5452. case 1:
  5453. response = _a.sent();
  5454. return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(auth, operationType, response)];
  5455. case 2:
  5456. userCredential = _a.sent();
  5457. if (!!bypassAuthState) return [3 /*break*/, 4];
  5458. return [4 /*yield*/, auth._updateCurrentUser(userCredential.user)];
  5459. case 3:
  5460. _a.sent();
  5461. _a.label = 4;
  5462. case 4: return [2 /*return*/, userCredential];
  5463. }
  5464. });
  5465. });
  5466. }
  5467. /**
  5468. * Asynchronously signs in with the given credentials.
  5469. *
  5470. * @remarks
  5471. * An {@link AuthProvider} can be used to generate the credential.
  5472. *
  5473. * @param auth - The {@link Auth} instance.
  5474. * @param credential - The auth credential.
  5475. *
  5476. * @public
  5477. */
  5478. function signInWithCredential(auth, credential) {
  5479. return tslib.__awaiter(this, void 0, void 0, function () {
  5480. return tslib.__generator(this, function (_a) {
  5481. return [2 /*return*/, _signInWithCredential(_castAuth(auth), credential)];
  5482. });
  5483. });
  5484. }
  5485. /**
  5486. * Links the user account with the given credentials.
  5487. *
  5488. * @remarks
  5489. * An {@link AuthProvider} can be used to generate the credential.
  5490. *
  5491. * @param user - The user.
  5492. * @param credential - The auth credential.
  5493. *
  5494. * @public
  5495. */
  5496. function linkWithCredential(user, credential) {
  5497. return tslib.__awaiter(this, void 0, void 0, function () {
  5498. var userInternal;
  5499. return tslib.__generator(this, function (_a) {
  5500. switch (_a.label) {
  5501. case 0:
  5502. userInternal = util.getModularInstance(user);
  5503. return [4 /*yield*/, _assertLinkedStatus(false, userInternal, credential.providerId)];
  5504. case 1:
  5505. _a.sent();
  5506. return [2 /*return*/, _link(userInternal, credential)];
  5507. }
  5508. });
  5509. });
  5510. }
  5511. /**
  5512. * Re-authenticates a user using a fresh credential.
  5513. *
  5514. * @remarks
  5515. * Use before operations such as {@link updatePassword} that require tokens from recent sign-in
  5516. * attempts. This method can be used to recover from a `CREDENTIAL_TOO_OLD_LOGIN_AGAIN` error.
  5517. *
  5518. * @param user - The user.
  5519. * @param credential - The auth credential.
  5520. *
  5521. * @public
  5522. */
  5523. function reauthenticateWithCredential(user, credential) {
  5524. return tslib.__awaiter(this, void 0, void 0, function () {
  5525. return tslib.__generator(this, function (_a) {
  5526. return [2 /*return*/, _reauthenticate(util.getModularInstance(user), credential)];
  5527. });
  5528. });
  5529. }
  5530. /**
  5531. * @license
  5532. * Copyright 2020 Google LLC
  5533. *
  5534. * Licensed under the Apache License, Version 2.0 (the "License");
  5535. * you may not use this file except in compliance with the License.
  5536. * You may obtain a copy of the License at
  5537. *
  5538. * http://www.apache.org/licenses/LICENSE-2.0
  5539. *
  5540. * Unless required by applicable law or agreed to in writing, software
  5541. * distributed under the License is distributed on an "AS IS" BASIS,
  5542. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5543. * See the License for the specific language governing permissions and
  5544. * limitations under the License.
  5545. */
  5546. function signInWithCustomToken$1(auth, request) {
  5547. return tslib.__awaiter(this, void 0, void 0, function () {
  5548. return tslib.__generator(this, function (_a) {
  5549. return [2 /*return*/, _performSignInRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:signInWithCustomToken" /* Endpoint.SIGN_IN_WITH_CUSTOM_TOKEN */, _addTidIfNecessary(auth, request))];
  5550. });
  5551. });
  5552. }
  5553. /**
  5554. * @license
  5555. * Copyright 2020 Google LLC
  5556. *
  5557. * Licensed under the Apache License, Version 2.0 (the "License");
  5558. * you may not use this file except in compliance with the License.
  5559. * You may obtain a copy of the License at
  5560. *
  5561. * http://www.apache.org/licenses/LICENSE-2.0
  5562. *
  5563. * Unless required by applicable law or agreed to in writing, software
  5564. * distributed under the License is distributed on an "AS IS" BASIS,
  5565. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5566. * See the License for the specific language governing permissions and
  5567. * limitations under the License.
  5568. */
  5569. /**
  5570. * Asynchronously signs in using a custom token.
  5571. *
  5572. * @remarks
  5573. * Custom tokens are used to integrate Firebase Auth with existing auth systems, and must
  5574. * be generated by an auth backend using the
  5575. * {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createcustomtoken | createCustomToken}
  5576. * method in the {@link https://firebase.google.com/docs/auth/admin | Admin SDK} .
  5577. *
  5578. * Fails with an error if the token is invalid, expired, or not accepted by the Firebase Auth service.
  5579. *
  5580. * @param auth - The {@link Auth} instance.
  5581. * @param customToken - The custom token to sign in with.
  5582. *
  5583. * @public
  5584. */
  5585. function signInWithCustomToken(auth, customToken) {
  5586. return tslib.__awaiter(this, void 0, void 0, function () {
  5587. var authInternal, response, cred;
  5588. return tslib.__generator(this, function (_a) {
  5589. switch (_a.label) {
  5590. case 0:
  5591. authInternal = _castAuth(auth);
  5592. return [4 /*yield*/, signInWithCustomToken$1(authInternal, {
  5593. token: customToken,
  5594. returnSecureToken: true
  5595. })];
  5596. case 1:
  5597. response = _a.sent();
  5598. return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
  5599. case 2:
  5600. cred = _a.sent();
  5601. return [4 /*yield*/, authInternal._updateCurrentUser(cred.user)];
  5602. case 3:
  5603. _a.sent();
  5604. return [2 /*return*/, cred];
  5605. }
  5606. });
  5607. });
  5608. }
  5609. /**
  5610. * @license
  5611. * Copyright 2020 Google LLC
  5612. *
  5613. * Licensed under the Apache License, Version 2.0 (the "License");
  5614. * you may not use this file except in compliance with the License.
  5615. * You may obtain a copy of the License at
  5616. *
  5617. * http://www.apache.org/licenses/LICENSE-2.0
  5618. *
  5619. * Unless required by applicable law or agreed to in writing, software
  5620. * distributed under the License is distributed on an "AS IS" BASIS,
  5621. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5622. * See the License for the specific language governing permissions and
  5623. * limitations under the License.
  5624. */
  5625. var MultiFactorInfoImpl = /** @class */ (function () {
  5626. function MultiFactorInfoImpl(factorId, response) {
  5627. this.factorId = factorId;
  5628. this.uid = response.mfaEnrollmentId;
  5629. this.enrollmentTime = new Date(response.enrolledAt).toUTCString();
  5630. this.displayName = response.displayName;
  5631. }
  5632. MultiFactorInfoImpl._fromServerResponse = function (auth, enrollment) {
  5633. if ('phoneInfo' in enrollment) {
  5634. return PhoneMultiFactorInfoImpl._fromServerResponse(auth, enrollment);
  5635. }
  5636. return _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5637. };
  5638. return MultiFactorInfoImpl;
  5639. }());
  5640. var PhoneMultiFactorInfoImpl = /** @class */ (function (_super) {
  5641. tslib.__extends(PhoneMultiFactorInfoImpl, _super);
  5642. function PhoneMultiFactorInfoImpl(response) {
  5643. var _this = _super.call(this, "phone" /* FactorId.PHONE */, response) || this;
  5644. _this.phoneNumber = response.phoneInfo;
  5645. return _this;
  5646. }
  5647. PhoneMultiFactorInfoImpl._fromServerResponse = function (_auth, enrollment) {
  5648. return new PhoneMultiFactorInfoImpl(enrollment);
  5649. };
  5650. return PhoneMultiFactorInfoImpl;
  5651. }(MultiFactorInfoImpl));
  5652. /**
  5653. * @license
  5654. * Copyright 2020 Google LLC
  5655. *
  5656. * Licensed under the Apache License, Version 2.0 (the "License");
  5657. * you may not use this file except in compliance with the License.
  5658. * You may obtain a copy of the License at
  5659. *
  5660. * http://www.apache.org/licenses/LICENSE-2.0
  5661. *
  5662. * Unless required by applicable law or agreed to in writing, software
  5663. * distributed under the License is distributed on an "AS IS" BASIS,
  5664. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5665. * See the License for the specific language governing permissions and
  5666. * limitations under the License.
  5667. */
  5668. function _setActionCodeSettingsOnRequest(auth, request, actionCodeSettings) {
  5669. var _a;
  5670. _assert(((_a = actionCodeSettings.url) === null || _a === void 0 ? void 0 : _a.length) > 0, auth, "invalid-continue-uri" /* AuthErrorCode.INVALID_CONTINUE_URI */);
  5671. _assert(typeof actionCodeSettings.dynamicLinkDomain === 'undefined' ||
  5672. actionCodeSettings.dynamicLinkDomain.length > 0, auth, "invalid-dynamic-link-domain" /* AuthErrorCode.INVALID_DYNAMIC_LINK_DOMAIN */);
  5673. request.continueUrl = actionCodeSettings.url;
  5674. request.dynamicLinkDomain = actionCodeSettings.dynamicLinkDomain;
  5675. request.canHandleCodeInApp = actionCodeSettings.handleCodeInApp;
  5676. if (actionCodeSettings.iOS) {
  5677. _assert(actionCodeSettings.iOS.bundleId.length > 0, auth, "missing-ios-bundle-id" /* AuthErrorCode.MISSING_IOS_BUNDLE_ID */);
  5678. request.iOSBundleId = actionCodeSettings.iOS.bundleId;
  5679. }
  5680. if (actionCodeSettings.android) {
  5681. _assert(actionCodeSettings.android.packageName.length > 0, auth, "missing-android-pkg-name" /* AuthErrorCode.MISSING_ANDROID_PACKAGE_NAME */);
  5682. request.androidInstallApp = actionCodeSettings.android.installApp;
  5683. request.androidMinimumVersionCode =
  5684. actionCodeSettings.android.minimumVersion;
  5685. request.androidPackageName = actionCodeSettings.android.packageName;
  5686. }
  5687. }
  5688. /**
  5689. * @license
  5690. * Copyright 2020 Google LLC
  5691. *
  5692. * Licensed under the Apache License, Version 2.0 (the "License");
  5693. * you may not use this file except in compliance with the License.
  5694. * You may obtain a copy of the License at
  5695. *
  5696. * http://www.apache.org/licenses/LICENSE-2.0
  5697. *
  5698. * Unless required by applicable law or agreed to in writing, software
  5699. * distributed under the License is distributed on an "AS IS" BASIS,
  5700. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5701. * See the License for the specific language governing permissions and
  5702. * limitations under the License.
  5703. */
  5704. /**
  5705. * Sends a password reset email to the given email address.
  5706. *
  5707. * @remarks
  5708. * To complete the password reset, call {@link confirmPasswordReset} with the code supplied in
  5709. * the email sent to the user, along with the new password specified by the user.
  5710. *
  5711. * @example
  5712. * ```javascript
  5713. * const actionCodeSettings = {
  5714. * url: 'https://www.example.com/?email=user@example.com',
  5715. * iOS: {
  5716. * bundleId: 'com.example.ios'
  5717. * },
  5718. * android: {
  5719. * packageName: 'com.example.android',
  5720. * installApp: true,
  5721. * minimumVersion: '12'
  5722. * },
  5723. * handleCodeInApp: true
  5724. * };
  5725. * await sendPasswordResetEmail(auth, 'user@example.com', actionCodeSettings);
  5726. * // Obtain code from user.
  5727. * await confirmPasswordReset('user@example.com', code);
  5728. * ```
  5729. *
  5730. * @param auth - The {@link Auth} instance.
  5731. * @param email - The user's email address.
  5732. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  5733. *
  5734. * @public
  5735. */
  5736. function sendPasswordResetEmail(auth, email, actionCodeSettings) {
  5737. return tslib.__awaiter(this, void 0, void 0, function () {
  5738. var authModular, request;
  5739. return tslib.__generator(this, function (_a) {
  5740. switch (_a.label) {
  5741. case 0:
  5742. authModular = util.getModularInstance(auth);
  5743. request = {
  5744. requestType: "PASSWORD_RESET" /* ActionCodeOperation.PASSWORD_RESET */,
  5745. email: email
  5746. };
  5747. if (actionCodeSettings) {
  5748. _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
  5749. }
  5750. return [4 /*yield*/, sendPasswordResetEmail$1(authModular, request)];
  5751. case 1:
  5752. _a.sent();
  5753. return [2 /*return*/];
  5754. }
  5755. });
  5756. });
  5757. }
  5758. /**
  5759. * Completes the password reset process, given a confirmation code and new password.
  5760. *
  5761. * @param auth - The {@link Auth} instance.
  5762. * @param oobCode - A confirmation code sent to the user.
  5763. * @param newPassword - The new password.
  5764. *
  5765. * @public
  5766. */
  5767. function confirmPasswordReset(auth, oobCode, newPassword) {
  5768. return tslib.__awaiter(this, void 0, void 0, function () {
  5769. return tslib.__generator(this, function (_a) {
  5770. switch (_a.label) {
  5771. case 0: return [4 /*yield*/, resetPassword(util.getModularInstance(auth), {
  5772. oobCode: oobCode,
  5773. newPassword: newPassword
  5774. })];
  5775. case 1:
  5776. _a.sent();
  5777. return [2 /*return*/];
  5778. }
  5779. });
  5780. });
  5781. }
  5782. /**
  5783. * Applies a verification code sent to the user by email or other out-of-band mechanism.
  5784. *
  5785. * @param auth - The {@link Auth} instance.
  5786. * @param oobCode - A verification code sent to the user.
  5787. *
  5788. * @public
  5789. */
  5790. function applyActionCode(auth, oobCode) {
  5791. return tslib.__awaiter(this, void 0, void 0, function () {
  5792. return tslib.__generator(this, function (_a) {
  5793. switch (_a.label) {
  5794. case 0: return [4 /*yield*/, applyActionCode$1(util.getModularInstance(auth), { oobCode: oobCode })];
  5795. case 1:
  5796. _a.sent();
  5797. return [2 /*return*/];
  5798. }
  5799. });
  5800. });
  5801. }
  5802. /**
  5803. * Checks a verification code sent to the user by email or other out-of-band mechanism.
  5804. *
  5805. * @returns metadata about the code.
  5806. *
  5807. * @param auth - The {@link Auth} instance.
  5808. * @param oobCode - A verification code sent to the user.
  5809. *
  5810. * @public
  5811. */
  5812. function checkActionCode(auth, oobCode) {
  5813. return tslib.__awaiter(this, void 0, void 0, function () {
  5814. var authModular, response, operation, multiFactorInfo;
  5815. return tslib.__generator(this, function (_a) {
  5816. switch (_a.label) {
  5817. case 0:
  5818. authModular = util.getModularInstance(auth);
  5819. return [4 /*yield*/, resetPassword(authModular, { oobCode: oobCode })];
  5820. case 1:
  5821. response = _a.sent();
  5822. operation = response.requestType;
  5823. _assert(operation, authModular, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5824. switch (operation) {
  5825. case "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */:
  5826. break;
  5827. case "VERIFY_AND_CHANGE_EMAIL" /* ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL */:
  5828. _assert(response.newEmail, authModular, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5829. break;
  5830. case "REVERT_SECOND_FACTOR_ADDITION" /* ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION */:
  5831. _assert(response.mfaInfo, authModular, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5832. // fall through
  5833. default:
  5834. _assert(response.email, authModular, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  5835. }
  5836. multiFactorInfo = null;
  5837. if (response.mfaInfo) {
  5838. multiFactorInfo = MultiFactorInfoImpl._fromServerResponse(_castAuth(authModular), response.mfaInfo);
  5839. }
  5840. return [2 /*return*/, {
  5841. data: {
  5842. email: (response.requestType === "VERIFY_AND_CHANGE_EMAIL" /* ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL */
  5843. ? response.newEmail
  5844. : response.email) || null,
  5845. previousEmail: (response.requestType === "VERIFY_AND_CHANGE_EMAIL" /* ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL */
  5846. ? response.email
  5847. : response.newEmail) || null,
  5848. multiFactorInfo: multiFactorInfo
  5849. },
  5850. operation: operation
  5851. }];
  5852. }
  5853. });
  5854. });
  5855. }
  5856. /**
  5857. * Checks a password reset code sent to the user by email or other out-of-band mechanism.
  5858. *
  5859. * @returns the user's email address if valid.
  5860. *
  5861. * @param auth - The {@link Auth} instance.
  5862. * @param code - A verification code sent to the user.
  5863. *
  5864. * @public
  5865. */
  5866. function verifyPasswordResetCode(auth, code) {
  5867. return tslib.__awaiter(this, void 0, void 0, function () {
  5868. var data;
  5869. return tslib.__generator(this, function (_a) {
  5870. switch (_a.label) {
  5871. case 0: return [4 /*yield*/, checkActionCode(util.getModularInstance(auth), code)];
  5872. case 1:
  5873. data = (_a.sent()).data;
  5874. // Email should always be present since a code was sent to it
  5875. return [2 /*return*/, data.email];
  5876. }
  5877. });
  5878. });
  5879. }
  5880. /**
  5881. * Creates a new user account associated with the specified email address and password.
  5882. *
  5883. * @remarks
  5884. * On successful creation of the user account, this user will also be signed in to your application.
  5885. *
  5886. * User account creation can fail if the account already exists or the password is invalid.
  5887. *
  5888. * Note: The email address acts as a unique identifier for the user and enables an email-based
  5889. * password reset. This function will create a new user account and set the initial user password.
  5890. *
  5891. * @param auth - The {@link Auth} instance.
  5892. * @param email - The user's email address.
  5893. * @param password - The user's chosen password.
  5894. *
  5895. * @public
  5896. */
  5897. function createUserWithEmailAndPassword(auth, email, password) {
  5898. return tslib.__awaiter(this, void 0, void 0, function () {
  5899. var authInternal, response, userCredential;
  5900. return tslib.__generator(this, function (_a) {
  5901. switch (_a.label) {
  5902. case 0:
  5903. authInternal = _castAuth(auth);
  5904. return [4 /*yield*/, signUp(authInternal, {
  5905. returnSecureToken: true,
  5906. email: email,
  5907. password: password
  5908. })];
  5909. case 1:
  5910. response = _a.sent();
  5911. return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
  5912. case 2:
  5913. userCredential = _a.sent();
  5914. return [4 /*yield*/, authInternal._updateCurrentUser(userCredential.user)];
  5915. case 3:
  5916. _a.sent();
  5917. return [2 /*return*/, userCredential];
  5918. }
  5919. });
  5920. });
  5921. }
  5922. /**
  5923. * Asynchronously signs in using an email and password.
  5924. *
  5925. * @remarks
  5926. * Fails with an error if the email address and password do not match.
  5927. *
  5928. * Note: The user's password is NOT the password used to access the user's email account. The
  5929. * email address serves as a unique identifier for the user, and the password is used to access
  5930. * the user's account in your Firebase project. See also: {@link createUserWithEmailAndPassword}.
  5931. *
  5932. * @param auth - The {@link Auth} instance.
  5933. * @param email - The users email address.
  5934. * @param password - The users password.
  5935. *
  5936. * @public
  5937. */
  5938. function signInWithEmailAndPassword(auth, email, password) {
  5939. return signInWithCredential(util.getModularInstance(auth), EmailAuthProvider.credential(email, password));
  5940. }
  5941. /**
  5942. * @license
  5943. * Copyright 2020 Google LLC
  5944. *
  5945. * Licensed under the Apache License, Version 2.0 (the "License");
  5946. * you may not use this file except in compliance with the License.
  5947. * You may obtain a copy of the License at
  5948. *
  5949. * http://www.apache.org/licenses/LICENSE-2.0
  5950. *
  5951. * Unless required by applicable law or agreed to in writing, software
  5952. * distributed under the License is distributed on an "AS IS" BASIS,
  5953. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5954. * See the License for the specific language governing permissions and
  5955. * limitations under the License.
  5956. */
  5957. /**
  5958. * Sends a sign-in email link to the user with the specified email.
  5959. *
  5960. * @remarks
  5961. * The sign-in operation has to always be completed in the app unlike other out of band email
  5962. * actions (password reset and email verifications). This is because, at the end of the flow,
  5963. * the user is expected to be signed in and their Auth state persisted within the app.
  5964. *
  5965. * To complete sign in with the email link, call {@link signInWithEmailLink} with the email
  5966. * address and the email link supplied in the email sent to the user.
  5967. *
  5968. * @example
  5969. * ```javascript
  5970. * const actionCodeSettings = {
  5971. * url: 'https://www.example.com/?email=user@example.com',
  5972. * iOS: {
  5973. * bundleId: 'com.example.ios'
  5974. * },
  5975. * android: {
  5976. * packageName: 'com.example.android',
  5977. * installApp: true,
  5978. * minimumVersion: '12'
  5979. * },
  5980. * handleCodeInApp: true
  5981. * };
  5982. * await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
  5983. * // Obtain emailLink from the user.
  5984. * if(isSignInWithEmailLink(auth, emailLink)) {
  5985. * await signInWithEmailLink(auth, 'user@example.com', emailLink);
  5986. * }
  5987. * ```
  5988. *
  5989. * @param authInternal - The {@link Auth} instance.
  5990. * @param email - The user's email address.
  5991. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  5992. *
  5993. * @public
  5994. */
  5995. function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
  5996. return tslib.__awaiter(this, void 0, void 0, function () {
  5997. var authModular, request;
  5998. return tslib.__generator(this, function (_a) {
  5999. switch (_a.label) {
  6000. case 0:
  6001. authModular = util.getModularInstance(auth);
  6002. request = {
  6003. requestType: "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */,
  6004. email: email
  6005. };
  6006. _assert(actionCodeSettings.handleCodeInApp, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  6007. if (actionCodeSettings) {
  6008. _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
  6009. }
  6010. return [4 /*yield*/, sendSignInLinkToEmail$1(authModular, request)];
  6011. case 1:
  6012. _a.sent();
  6013. return [2 /*return*/];
  6014. }
  6015. });
  6016. });
  6017. }
  6018. /**
  6019. * Checks if an incoming link is a sign-in with email link suitable for {@link signInWithEmailLink}.
  6020. *
  6021. * @param auth - The {@link Auth} instance.
  6022. * @param emailLink - The link sent to the user's email address.
  6023. *
  6024. * @public
  6025. */
  6026. function isSignInWithEmailLink(auth, emailLink) {
  6027. var actionCodeUrl = ActionCodeURL.parseLink(emailLink);
  6028. return (actionCodeUrl === null || actionCodeUrl === void 0 ? void 0 : actionCodeUrl.operation) === "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */;
  6029. }
  6030. /**
  6031. * Asynchronously signs in using an email and sign-in email link.
  6032. *
  6033. * @remarks
  6034. * If no link is passed, the link is inferred from the current URL.
  6035. *
  6036. * Fails with an error if the email address is invalid or OTP in email link expires.
  6037. *
  6038. * Note: Confirm the link is a sign-in email link before calling this method firebase.auth.Auth.isSignInWithEmailLink.
  6039. *
  6040. * @example
  6041. * ```javascript
  6042. * const actionCodeSettings = {
  6043. * url: 'https://www.example.com/?email=user@example.com',
  6044. * iOS: {
  6045. * bundleId: 'com.example.ios'
  6046. * },
  6047. * android: {
  6048. * packageName: 'com.example.android',
  6049. * installApp: true,
  6050. * minimumVersion: '12'
  6051. * },
  6052. * handleCodeInApp: true
  6053. * };
  6054. * await sendSignInLinkToEmail(auth, 'user@example.com', actionCodeSettings);
  6055. * // Obtain emailLink from the user.
  6056. * if(isSignInWithEmailLink(auth, emailLink)) {
  6057. * await signInWithEmailLink(auth, 'user@example.com', emailLink);
  6058. * }
  6059. * ```
  6060. *
  6061. * @param auth - The {@link Auth} instance.
  6062. * @param email - The user's email address.
  6063. * @param emailLink - The link sent to the user's email address.
  6064. *
  6065. * @public
  6066. */
  6067. function signInWithEmailLink(auth, email, emailLink) {
  6068. return tslib.__awaiter(this, void 0, void 0, function () {
  6069. var authModular, credential;
  6070. return tslib.__generator(this, function (_a) {
  6071. authModular = util.getModularInstance(auth);
  6072. credential = EmailAuthProvider.credentialWithLink(email, emailLink || _getCurrentUrl());
  6073. // Check if the tenant ID in the email link matches the tenant ID on Auth
  6074. // instance.
  6075. _assert(credential._tenantId === (authModular.tenantId || null), authModular, "tenant-id-mismatch" /* AuthErrorCode.TENANT_ID_MISMATCH */);
  6076. return [2 /*return*/, signInWithCredential(authModular, credential)];
  6077. });
  6078. });
  6079. }
  6080. /**
  6081. * @license
  6082. * Copyright 2020 Google LLC
  6083. *
  6084. * Licensed under the Apache License, Version 2.0 (the "License");
  6085. * you may not use this file except in compliance with the License.
  6086. * You may obtain a copy of the License at
  6087. *
  6088. * http://www.apache.org/licenses/LICENSE-2.0
  6089. *
  6090. * Unless required by applicable law or agreed to in writing, software
  6091. * distributed under the License is distributed on an "AS IS" BASIS,
  6092. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6093. * See the License for the specific language governing permissions and
  6094. * limitations under the License.
  6095. */
  6096. function createAuthUri(auth, request) {
  6097. return tslib.__awaiter(this, void 0, void 0, function () {
  6098. return tslib.__generator(this, function (_a) {
  6099. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:createAuthUri" /* Endpoint.CREATE_AUTH_URI */, _addTidIfNecessary(auth, request))];
  6100. });
  6101. });
  6102. }
  6103. /**
  6104. * @license
  6105. * Copyright 2020 Google LLC
  6106. *
  6107. * Licensed under the Apache License, Version 2.0 (the "License");
  6108. * you may not use this file except in compliance with the License.
  6109. * You may obtain a copy of the License at
  6110. *
  6111. * http://www.apache.org/licenses/LICENSE-2.0
  6112. *
  6113. * Unless required by applicable law or agreed to in writing, software
  6114. * distributed under the License is distributed on an "AS IS" BASIS,
  6115. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6116. * See the License for the specific language governing permissions and
  6117. * limitations under the License.
  6118. */
  6119. /**
  6120. * Gets the list of possible sign in methods for the given email address.
  6121. *
  6122. * @remarks
  6123. * This is useful to differentiate methods of sign-in for the same provider, eg.
  6124. * {@link EmailAuthProvider} which has 2 methods of sign-in,
  6125. * {@link SignInMethod}.EMAIL_PASSWORD and
  6126. * {@link SignInMethod}.EMAIL_LINK.
  6127. *
  6128. * @param auth - The {@link Auth} instance.
  6129. * @param email - The user's email address.
  6130. *
  6131. * @public
  6132. */
  6133. function fetchSignInMethodsForEmail(auth, email) {
  6134. return tslib.__awaiter(this, void 0, void 0, function () {
  6135. var continueUri, request, signinMethods;
  6136. return tslib.__generator(this, function (_a) {
  6137. switch (_a.label) {
  6138. case 0:
  6139. continueUri = _isHttpOrHttps() ? _getCurrentUrl() : 'http://localhost';
  6140. request = {
  6141. identifier: email,
  6142. continueUri: continueUri
  6143. };
  6144. return [4 /*yield*/, createAuthUri(util.getModularInstance(auth), request)];
  6145. case 1:
  6146. signinMethods = (_a.sent()).signinMethods;
  6147. return [2 /*return*/, signinMethods || []];
  6148. }
  6149. });
  6150. });
  6151. }
  6152. /**
  6153. * Sends a verification email to a user.
  6154. *
  6155. * @remarks
  6156. * The verification process is completed by calling {@link applyActionCode}.
  6157. *
  6158. * @example
  6159. * ```javascript
  6160. * const actionCodeSettings = {
  6161. * url: 'https://www.example.com/?email=user@example.com',
  6162. * iOS: {
  6163. * bundleId: 'com.example.ios'
  6164. * },
  6165. * android: {
  6166. * packageName: 'com.example.android',
  6167. * installApp: true,
  6168. * minimumVersion: '12'
  6169. * },
  6170. * handleCodeInApp: true
  6171. * };
  6172. * await sendEmailVerification(user, actionCodeSettings);
  6173. * // Obtain code from the user.
  6174. * await applyActionCode(auth, code);
  6175. * ```
  6176. *
  6177. * @param user - The user.
  6178. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  6179. *
  6180. * @public
  6181. */
  6182. function sendEmailVerification(user, actionCodeSettings) {
  6183. return tslib.__awaiter(this, void 0, void 0, function () {
  6184. var userInternal, idToken, request, email;
  6185. return tslib.__generator(this, function (_a) {
  6186. switch (_a.label) {
  6187. case 0:
  6188. userInternal = util.getModularInstance(user);
  6189. return [4 /*yield*/, user.getIdToken()];
  6190. case 1:
  6191. idToken = _a.sent();
  6192. request = {
  6193. requestType: "VERIFY_EMAIL" /* ActionCodeOperation.VERIFY_EMAIL */,
  6194. idToken: idToken
  6195. };
  6196. if (actionCodeSettings) {
  6197. _setActionCodeSettingsOnRequest(userInternal.auth, request, actionCodeSettings);
  6198. }
  6199. return [4 /*yield*/, sendEmailVerification$1(userInternal.auth, request)];
  6200. case 2:
  6201. email = (_a.sent()).email;
  6202. if (!(email !== user.email)) return [3 /*break*/, 4];
  6203. return [4 /*yield*/, user.reload()];
  6204. case 3:
  6205. _a.sent();
  6206. _a.label = 4;
  6207. case 4: return [2 /*return*/];
  6208. }
  6209. });
  6210. });
  6211. }
  6212. /**
  6213. * Sends a verification email to a new email address.
  6214. *
  6215. * @remarks
  6216. * The user's email will be updated to the new one after being verified.
  6217. *
  6218. * If you have a custom email action handler, you can complete the verification process by calling
  6219. * {@link applyActionCode}.
  6220. *
  6221. * @example
  6222. * ```javascript
  6223. * const actionCodeSettings = {
  6224. * url: 'https://www.example.com/?email=user@example.com',
  6225. * iOS: {
  6226. * bundleId: 'com.example.ios'
  6227. * },
  6228. * android: {
  6229. * packageName: 'com.example.android',
  6230. * installApp: true,
  6231. * minimumVersion: '12'
  6232. * },
  6233. * handleCodeInApp: true
  6234. * };
  6235. * await verifyBeforeUpdateEmail(user, 'newemail@example.com', actionCodeSettings);
  6236. * // Obtain code from the user.
  6237. * await applyActionCode(auth, code);
  6238. * ```
  6239. *
  6240. * @param user - The user.
  6241. * @param newEmail - The new email address to be verified before update.
  6242. * @param actionCodeSettings - The {@link ActionCodeSettings}.
  6243. *
  6244. * @public
  6245. */
  6246. function verifyBeforeUpdateEmail(user, newEmail, actionCodeSettings) {
  6247. return tslib.__awaiter(this, void 0, void 0, function () {
  6248. var userInternal, idToken, request, email;
  6249. return tslib.__generator(this, function (_a) {
  6250. switch (_a.label) {
  6251. case 0:
  6252. userInternal = util.getModularInstance(user);
  6253. return [4 /*yield*/, user.getIdToken()];
  6254. case 1:
  6255. idToken = _a.sent();
  6256. request = {
  6257. requestType: "VERIFY_AND_CHANGE_EMAIL" /* ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL */,
  6258. idToken: idToken,
  6259. newEmail: newEmail
  6260. };
  6261. if (actionCodeSettings) {
  6262. _setActionCodeSettingsOnRequest(userInternal.auth, request, actionCodeSettings);
  6263. }
  6264. return [4 /*yield*/, verifyAndChangeEmail(userInternal.auth, request)];
  6265. case 2:
  6266. email = (_a.sent()).email;
  6267. if (!(email !== user.email)) return [3 /*break*/, 4];
  6268. // If the local copy of the email on user is outdated, reload the
  6269. // user.
  6270. return [4 /*yield*/, user.reload()];
  6271. case 3:
  6272. // If the local copy of the email on user is outdated, reload the
  6273. // user.
  6274. _a.sent();
  6275. _a.label = 4;
  6276. case 4: return [2 /*return*/];
  6277. }
  6278. });
  6279. });
  6280. }
  6281. /**
  6282. * @license
  6283. * Copyright 2020 Google LLC
  6284. *
  6285. * Licensed under the Apache License, Version 2.0 (the "License");
  6286. * you may not use this file except in compliance with the License.
  6287. * You may obtain a copy of the License at
  6288. *
  6289. * http://www.apache.org/licenses/LICENSE-2.0
  6290. *
  6291. * Unless required by applicable law or agreed to in writing, software
  6292. * distributed under the License is distributed on an "AS IS" BASIS,
  6293. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6294. * See the License for the specific language governing permissions and
  6295. * limitations under the License.
  6296. */
  6297. function updateProfile$1(auth, request) {
  6298. return tslib.__awaiter(this, void 0, void 0, function () {
  6299. return tslib.__generator(this, function (_a) {
  6300. return [2 /*return*/, _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v1/accounts:update" /* Endpoint.SET_ACCOUNT_INFO */, request)];
  6301. });
  6302. });
  6303. }
  6304. /**
  6305. * @license
  6306. * Copyright 2020 Google LLC
  6307. *
  6308. * Licensed under the Apache License, Version 2.0 (the "License");
  6309. * you may not use this file except in compliance with the License.
  6310. * You may obtain a copy of the License at
  6311. *
  6312. * http://www.apache.org/licenses/LICENSE-2.0
  6313. *
  6314. * Unless required by applicable law or agreed to in writing, software
  6315. * distributed under the License is distributed on an "AS IS" BASIS,
  6316. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6317. * See the License for the specific language governing permissions and
  6318. * limitations under the License.
  6319. */
  6320. /**
  6321. * Updates a user's profile data.
  6322. *
  6323. * @param user - The user.
  6324. * @param profile - The profile's `displayName` and `photoURL` to update.
  6325. *
  6326. * @public
  6327. */
  6328. function updateProfile(user, _a) {
  6329. var displayName = _a.displayName, photoUrl = _a.photoURL;
  6330. return tslib.__awaiter(this, void 0, void 0, function () {
  6331. var userInternal, idToken, profileRequest, response, passwordProvider;
  6332. return tslib.__generator(this, function (_b) {
  6333. switch (_b.label) {
  6334. case 0:
  6335. if (displayName === undefined && photoUrl === undefined) {
  6336. return [2 /*return*/];
  6337. }
  6338. userInternal = util.getModularInstance(user);
  6339. return [4 /*yield*/, userInternal.getIdToken()];
  6340. case 1:
  6341. idToken = _b.sent();
  6342. profileRequest = {
  6343. idToken: idToken,
  6344. displayName: displayName,
  6345. photoUrl: photoUrl,
  6346. returnSecureToken: true
  6347. };
  6348. return [4 /*yield*/, _logoutIfInvalidated(userInternal, updateProfile$1(userInternal.auth, profileRequest))];
  6349. case 2:
  6350. response = _b.sent();
  6351. userInternal.displayName = response.displayName || null;
  6352. userInternal.photoURL = response.photoUrl || null;
  6353. passwordProvider = userInternal.providerData.find(function (_a) {
  6354. var providerId = _a.providerId;
  6355. return providerId === "password" /* ProviderId.PASSWORD */;
  6356. });
  6357. if (passwordProvider) {
  6358. passwordProvider.displayName = userInternal.displayName;
  6359. passwordProvider.photoURL = userInternal.photoURL;
  6360. }
  6361. return [4 /*yield*/, userInternal._updateTokensIfNecessary(response)];
  6362. case 3:
  6363. _b.sent();
  6364. return [2 /*return*/];
  6365. }
  6366. });
  6367. });
  6368. }
  6369. /**
  6370. * Updates the user's email address.
  6371. *
  6372. * @remarks
  6373. * An email will be sent to the original email address (if it was set) that allows to revoke the
  6374. * email address change, in order to protect them from account hijacking.
  6375. *
  6376. * Important: this is a security sensitive operation that requires the user to have recently signed
  6377. * in. If this requirement isn't met, ask the user to authenticate again and then call
  6378. * {@link reauthenticateWithCredential}.
  6379. *
  6380. * @param user - The user.
  6381. * @param newEmail - The new email address.
  6382. *
  6383. * @public
  6384. */
  6385. function updateEmail(user, newEmail) {
  6386. return updateEmailOrPassword(util.getModularInstance(user), newEmail, null);
  6387. }
  6388. /**
  6389. * Updates the user's password.
  6390. *
  6391. * @remarks
  6392. * Important: this is a security sensitive operation that requires the user to have recently signed
  6393. * in. If this requirement isn't met, ask the user to authenticate again and then call
  6394. * {@link reauthenticateWithCredential}.
  6395. *
  6396. * @param user - The user.
  6397. * @param newPassword - The new password.
  6398. *
  6399. * @public
  6400. */
  6401. function updatePassword(user, newPassword) {
  6402. return updateEmailOrPassword(util.getModularInstance(user), null, newPassword);
  6403. }
  6404. function updateEmailOrPassword(user, email, password) {
  6405. return tslib.__awaiter(this, void 0, void 0, function () {
  6406. var auth, idToken, request, response;
  6407. return tslib.__generator(this, function (_a) {
  6408. switch (_a.label) {
  6409. case 0:
  6410. auth = user.auth;
  6411. return [4 /*yield*/, user.getIdToken()];
  6412. case 1:
  6413. idToken = _a.sent();
  6414. request = {
  6415. idToken: idToken,
  6416. returnSecureToken: true
  6417. };
  6418. if (email) {
  6419. request.email = email;
  6420. }
  6421. if (password) {
  6422. request.password = password;
  6423. }
  6424. return [4 /*yield*/, _logoutIfInvalidated(user, updateEmailPassword(auth, request))];
  6425. case 2:
  6426. response = _a.sent();
  6427. return [4 /*yield*/, user._updateTokensIfNecessary(response, /* reload */ true)];
  6428. case 3:
  6429. _a.sent();
  6430. return [2 /*return*/];
  6431. }
  6432. });
  6433. });
  6434. }
  6435. /**
  6436. * @license
  6437. * Copyright 2019 Google LLC
  6438. *
  6439. * Licensed under the Apache License, Version 2.0 (the "License");
  6440. * you may not use this file except in compliance with the License.
  6441. * You may obtain a copy of the License at
  6442. *
  6443. * http://www.apache.org/licenses/LICENSE-2.0
  6444. *
  6445. * Unless required by applicable law or agreed to in writing, software
  6446. * distributed under the License is distributed on an "AS IS" BASIS,
  6447. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6448. * See the License for the specific language governing permissions and
  6449. * limitations under the License.
  6450. */
  6451. /**
  6452. * Parse the `AdditionalUserInfo` from the ID token response.
  6453. *
  6454. */
  6455. function _fromIdTokenResponse(idTokenResponse) {
  6456. var _a, _b;
  6457. if (!idTokenResponse) {
  6458. return null;
  6459. }
  6460. var providerId = idTokenResponse.providerId;
  6461. var profile = idTokenResponse.rawUserInfo
  6462. ? JSON.parse(idTokenResponse.rawUserInfo)
  6463. : {};
  6464. var isNewUser = idTokenResponse.isNewUser ||
  6465. idTokenResponse.kind === "identitytoolkit#SignupNewUserResponse" /* IdTokenResponseKind.SignupNewUser */;
  6466. if (!providerId && (idTokenResponse === null || idTokenResponse === void 0 ? void 0 : idTokenResponse.idToken)) {
  6467. var signInProvider = (_b = (_a = _parseToken(idTokenResponse.idToken)) === null || _a === void 0 ? void 0 : _a.firebase) === null || _b === void 0 ? void 0 : _b['sign_in_provider'];
  6468. if (signInProvider) {
  6469. var filteredProviderId = signInProvider !== "anonymous" /* ProviderId.ANONYMOUS */ &&
  6470. signInProvider !== "custom" /* ProviderId.CUSTOM */
  6471. ? signInProvider
  6472. : null;
  6473. // Uses generic class in accordance with the legacy SDK.
  6474. return new GenericAdditionalUserInfo(isNewUser, filteredProviderId);
  6475. }
  6476. }
  6477. if (!providerId) {
  6478. return null;
  6479. }
  6480. switch (providerId) {
  6481. case "facebook.com" /* ProviderId.FACEBOOK */:
  6482. return new FacebookAdditionalUserInfo(isNewUser, profile);
  6483. case "github.com" /* ProviderId.GITHUB */:
  6484. return new GithubAdditionalUserInfo(isNewUser, profile);
  6485. case "google.com" /* ProviderId.GOOGLE */:
  6486. return new GoogleAdditionalUserInfo(isNewUser, profile);
  6487. case "twitter.com" /* ProviderId.TWITTER */:
  6488. return new TwitterAdditionalUserInfo(isNewUser, profile, idTokenResponse.screenName || null);
  6489. case "custom" /* ProviderId.CUSTOM */:
  6490. case "anonymous" /* ProviderId.ANONYMOUS */:
  6491. return new GenericAdditionalUserInfo(isNewUser, null);
  6492. default:
  6493. return new GenericAdditionalUserInfo(isNewUser, providerId, profile);
  6494. }
  6495. }
  6496. var GenericAdditionalUserInfo = /** @class */ (function () {
  6497. function GenericAdditionalUserInfo(isNewUser, providerId, profile) {
  6498. if (profile === void 0) { profile = {}; }
  6499. this.isNewUser = isNewUser;
  6500. this.providerId = providerId;
  6501. this.profile = profile;
  6502. }
  6503. return GenericAdditionalUserInfo;
  6504. }());
  6505. var FederatedAdditionalUserInfoWithUsername = /** @class */ (function (_super) {
  6506. tslib.__extends(FederatedAdditionalUserInfoWithUsername, _super);
  6507. function FederatedAdditionalUserInfoWithUsername(isNewUser, providerId, profile, username) {
  6508. var _this = _super.call(this, isNewUser, providerId, profile) || this;
  6509. _this.username = username;
  6510. return _this;
  6511. }
  6512. return FederatedAdditionalUserInfoWithUsername;
  6513. }(GenericAdditionalUserInfo));
  6514. var FacebookAdditionalUserInfo = /** @class */ (function (_super) {
  6515. tslib.__extends(FacebookAdditionalUserInfo, _super);
  6516. function FacebookAdditionalUserInfo(isNewUser, profile) {
  6517. return _super.call(this, isNewUser, "facebook.com" /* ProviderId.FACEBOOK */, profile) || this;
  6518. }
  6519. return FacebookAdditionalUserInfo;
  6520. }(GenericAdditionalUserInfo));
  6521. var GithubAdditionalUserInfo = /** @class */ (function (_super) {
  6522. tslib.__extends(GithubAdditionalUserInfo, _super);
  6523. function GithubAdditionalUserInfo(isNewUser, profile) {
  6524. return _super.call(this, isNewUser, "github.com" /* ProviderId.GITHUB */, profile, typeof (profile === null || profile === void 0 ? void 0 : profile.login) === 'string' ? profile === null || profile === void 0 ? void 0 : profile.login : null) || this;
  6525. }
  6526. return GithubAdditionalUserInfo;
  6527. }(FederatedAdditionalUserInfoWithUsername));
  6528. var GoogleAdditionalUserInfo = /** @class */ (function (_super) {
  6529. tslib.__extends(GoogleAdditionalUserInfo, _super);
  6530. function GoogleAdditionalUserInfo(isNewUser, profile) {
  6531. return _super.call(this, isNewUser, "google.com" /* ProviderId.GOOGLE */, profile) || this;
  6532. }
  6533. return GoogleAdditionalUserInfo;
  6534. }(GenericAdditionalUserInfo));
  6535. var TwitterAdditionalUserInfo = /** @class */ (function (_super) {
  6536. tslib.__extends(TwitterAdditionalUserInfo, _super);
  6537. function TwitterAdditionalUserInfo(isNewUser, profile, screenName) {
  6538. return _super.call(this, isNewUser, "twitter.com" /* ProviderId.TWITTER */, profile, screenName) || this;
  6539. }
  6540. return TwitterAdditionalUserInfo;
  6541. }(FederatedAdditionalUserInfoWithUsername));
  6542. /**
  6543. * Extracts provider specific {@link AdditionalUserInfo} for the given credential.
  6544. *
  6545. * @param userCredential - The user credential.
  6546. *
  6547. * @public
  6548. */
  6549. function getAdditionalUserInfo(userCredential) {
  6550. var _a = userCredential, user = _a.user, _tokenResponse = _a._tokenResponse;
  6551. if (user.isAnonymous && !_tokenResponse) {
  6552. // Handle the special case where signInAnonymously() gets called twice.
  6553. // No network call is made so there's nothing to actually fill this in
  6554. return {
  6555. providerId: null,
  6556. isNewUser: false,
  6557. profile: null
  6558. };
  6559. }
  6560. return _fromIdTokenResponse(_tokenResponse);
  6561. }
  6562. /**
  6563. * @license
  6564. * Copyright 2020 Google LLC
  6565. *
  6566. * Licensed under the Apache License, Version 2.0 (the "License");
  6567. * you may not use this file except in compliance with the License.
  6568. * You may obtain a copy of the License at
  6569. *
  6570. * http://www.apache.org/licenses/LICENSE-2.0
  6571. *
  6572. * Unless required by applicable law or agreed to in writing, software
  6573. * distributed under the License is distributed on an "AS IS" BASIS,
  6574. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6575. * See the License for the specific language governing permissions and
  6576. * limitations under the License.
  6577. */
  6578. // Non-optional auth methods.
  6579. /**
  6580. * Changes the type of persistence on the {@link Auth} instance for the currently saved
  6581. * `Auth` session and applies this type of persistence for future sign-in requests, including
  6582. * sign-in with redirect requests.
  6583. *
  6584. * @remarks
  6585. * This makes it easy for a user signing in to specify whether their session should be
  6586. * remembered or not. It also makes it easier to never persist the `Auth` state for applications
  6587. * that are shared by other users or have sensitive data.
  6588. *
  6589. * @example
  6590. * ```javascript
  6591. * setPersistence(auth, browserSessionPersistence);
  6592. * ```
  6593. *
  6594. * @param auth - The {@link Auth} instance.
  6595. * @param persistence - The {@link Persistence} to use.
  6596. * @returns A `Promise` that resolves once the persistence change has completed
  6597. *
  6598. * @public
  6599. */
  6600. function setPersistence(auth, persistence) {
  6601. return util.getModularInstance(auth).setPersistence(persistence);
  6602. }
  6603. /**
  6604. * Adds an observer for changes to the signed-in user's ID token.
  6605. *
  6606. * @remarks
  6607. * This includes sign-in, sign-out, and token refresh events.
  6608. *
  6609. * @param auth - The {@link Auth} instance.
  6610. * @param nextOrObserver - callback triggered on change.
  6611. * @param error - Deprecated. This callback is never triggered. Errors
  6612. * on signing in/out can be caught in promises returned from
  6613. * sign-in/sign-out functions.
  6614. * @param completed - Deprecated. This callback is never triggered.
  6615. *
  6616. * @public
  6617. */
  6618. function onIdTokenChanged(auth, nextOrObserver, error, completed) {
  6619. return util.getModularInstance(auth).onIdTokenChanged(nextOrObserver, error, completed);
  6620. }
  6621. /**
  6622. * Adds a blocking callback that runs before an auth state change
  6623. * sets a new user.
  6624. *
  6625. * @param auth - The {@link Auth} instance.
  6626. * @param callback - callback triggered before new user value is set.
  6627. * If this throws, it blocks the user from being set.
  6628. * @param onAbort - callback triggered if a later `beforeAuthStateChanged()`
  6629. * callback throws, allowing you to undo any side effects.
  6630. */
  6631. function beforeAuthStateChanged(auth, callback, onAbort) {
  6632. return util.getModularInstance(auth).beforeAuthStateChanged(callback, onAbort);
  6633. }
  6634. /**
  6635. * Adds an observer for changes to the user's sign-in state.
  6636. *
  6637. * @remarks
  6638. * To keep the old behavior, see {@link onIdTokenChanged}.
  6639. *
  6640. * @param auth - The {@link Auth} instance.
  6641. * @param nextOrObserver - callback triggered on change.
  6642. * @param error - Deprecated. This callback is never triggered. Errors
  6643. * on signing in/out can be caught in promises returned from
  6644. * sign-in/sign-out functions.
  6645. * @param completed - Deprecated. This callback is never triggered.
  6646. *
  6647. * @public
  6648. */
  6649. function onAuthStateChanged(auth, nextOrObserver, error, completed) {
  6650. return util.getModularInstance(auth).onAuthStateChanged(nextOrObserver, error, completed);
  6651. }
  6652. /**
  6653. * Sets the current language to the default device/browser preference.
  6654. *
  6655. * @param auth - The {@link Auth} instance.
  6656. *
  6657. * @public
  6658. */
  6659. function useDeviceLanguage(auth) {
  6660. util.getModularInstance(auth).useDeviceLanguage();
  6661. }
  6662. /**
  6663. * Asynchronously sets the provided user as {@link Auth.currentUser} on the
  6664. * {@link Auth} instance.
  6665. *
  6666. * @remarks
  6667. * A new instance copy of the user provided will be made and set as currentUser.
  6668. *
  6669. * This will trigger {@link onAuthStateChanged} and {@link onIdTokenChanged} listeners
  6670. * like other sign in methods.
  6671. *
  6672. * The operation fails with an error if the user to be updated belongs to a different Firebase
  6673. * project.
  6674. *
  6675. * @param auth - The {@link Auth} instance.
  6676. * @param user - The new {@link User}.
  6677. *
  6678. * @public
  6679. */
  6680. function updateCurrentUser(auth, user) {
  6681. return util.getModularInstance(auth).updateCurrentUser(user);
  6682. }
  6683. /**
  6684. * Signs out the current user.
  6685. *
  6686. * @param auth - The {@link Auth} instance.
  6687. *
  6688. * @public
  6689. */
  6690. function signOut(auth) {
  6691. return util.getModularInstance(auth).signOut();
  6692. }
  6693. /**
  6694. * Deletes and signs out the user.
  6695. *
  6696. * @remarks
  6697. * Important: this is a security-sensitive operation that requires the user to have recently
  6698. * signed in. If this requirement isn't met, ask the user to authenticate again and then call
  6699. * {@link reauthenticateWithCredential}.
  6700. *
  6701. * @param user - The user.
  6702. *
  6703. * @public
  6704. */
  6705. function deleteUser(user) {
  6706. return tslib.__awaiter(this, void 0, void 0, function () {
  6707. return tslib.__generator(this, function (_a) {
  6708. return [2 /*return*/, util.getModularInstance(user).delete()];
  6709. });
  6710. });
  6711. }
  6712. var MultiFactorSessionImpl = /** @class */ (function () {
  6713. function MultiFactorSessionImpl(type, credential, auth) {
  6714. this.type = type;
  6715. this.credential = credential;
  6716. this.auth = auth;
  6717. }
  6718. MultiFactorSessionImpl._fromIdtoken = function (idToken, auth) {
  6719. return new MultiFactorSessionImpl("enroll" /* MultiFactorSessionType.ENROLL */, idToken, auth);
  6720. };
  6721. MultiFactorSessionImpl._fromMfaPendingCredential = function (mfaPendingCredential) {
  6722. return new MultiFactorSessionImpl("signin" /* MultiFactorSessionType.SIGN_IN */, mfaPendingCredential);
  6723. };
  6724. MultiFactorSessionImpl.prototype.toJSON = function () {
  6725. var _a;
  6726. var key = this.type === "enroll" /* MultiFactorSessionType.ENROLL */
  6727. ? 'idToken'
  6728. : 'pendingCredential';
  6729. return {
  6730. multiFactorSession: (_a = {},
  6731. _a[key] = this.credential,
  6732. _a)
  6733. };
  6734. };
  6735. MultiFactorSessionImpl.fromJSON = function (obj) {
  6736. var _a, _b;
  6737. if (obj === null || obj === void 0 ? void 0 : obj.multiFactorSession) {
  6738. if ((_a = obj.multiFactorSession) === null || _a === void 0 ? void 0 : _a.pendingCredential) {
  6739. return MultiFactorSessionImpl._fromMfaPendingCredential(obj.multiFactorSession.pendingCredential);
  6740. }
  6741. else if ((_b = obj.multiFactorSession) === null || _b === void 0 ? void 0 : _b.idToken) {
  6742. return MultiFactorSessionImpl._fromIdtoken(obj.multiFactorSession.idToken);
  6743. }
  6744. }
  6745. return null;
  6746. };
  6747. return MultiFactorSessionImpl;
  6748. }());
  6749. /**
  6750. * @license
  6751. * Copyright 2020 Google LLC
  6752. *
  6753. * Licensed under the Apache License, Version 2.0 (the "License");
  6754. * you may not use this file except in compliance with the License.
  6755. * You may obtain a copy of the License at
  6756. *
  6757. * http://www.apache.org/licenses/LICENSE-2.0
  6758. *
  6759. * Unless required by applicable law or agreed to in writing, software
  6760. * distributed under the License is distributed on an "AS IS" BASIS,
  6761. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6762. * See the License for the specific language governing permissions and
  6763. * limitations under the License.
  6764. */
  6765. var MultiFactorResolverImpl = /** @class */ (function () {
  6766. function MultiFactorResolverImpl(session, hints, signInResolver) {
  6767. this.session = session;
  6768. this.hints = hints;
  6769. this.signInResolver = signInResolver;
  6770. }
  6771. /** @internal */
  6772. MultiFactorResolverImpl._fromError = function (authExtern, error) {
  6773. var _this = this;
  6774. var auth = _castAuth(authExtern);
  6775. var serverResponse = error.customData._serverResponse;
  6776. var hints = (serverResponse.mfaInfo || []).map(function (enrollment) {
  6777. return MultiFactorInfoImpl._fromServerResponse(auth, enrollment);
  6778. });
  6779. _assert(serverResponse.mfaPendingCredential, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  6780. var session = MultiFactorSessionImpl._fromMfaPendingCredential(serverResponse.mfaPendingCredential);
  6781. return new MultiFactorResolverImpl(session, hints, function (assertion) { return tslib.__awaiter(_this, void 0, void 0, function () {
  6782. var mfaResponse, idTokenResponse, _a, userCredential;
  6783. return tslib.__generator(this, function (_b) {
  6784. switch (_b.label) {
  6785. case 0: return [4 /*yield*/, assertion._process(auth, session)];
  6786. case 1:
  6787. mfaResponse = _b.sent();
  6788. // Clear out the unneeded fields from the old login response
  6789. delete serverResponse.mfaInfo;
  6790. delete serverResponse.mfaPendingCredential;
  6791. idTokenResponse = tslib.__assign(tslib.__assign({}, serverResponse), { idToken: mfaResponse.idToken, refreshToken: mfaResponse.refreshToken });
  6792. _a = error.operationType;
  6793. switch (_a) {
  6794. case "signIn" /* OperationType.SIGN_IN */: return [3 /*break*/, 2];
  6795. case "reauthenticate" /* OperationType.REAUTHENTICATE */: return [3 /*break*/, 5];
  6796. }
  6797. return [3 /*break*/, 6];
  6798. case 2: return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(auth, error.operationType, idTokenResponse)];
  6799. case 3:
  6800. userCredential = _b.sent();
  6801. return [4 /*yield*/, auth._updateCurrentUser(userCredential.user)];
  6802. case 4:
  6803. _b.sent();
  6804. return [2 /*return*/, userCredential];
  6805. case 5:
  6806. _assert(error.user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  6807. return [2 /*return*/, UserCredentialImpl._forOperation(error.user, error.operationType, idTokenResponse)];
  6808. case 6:
  6809. _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  6810. _b.label = 7;
  6811. case 7: return [2 /*return*/];
  6812. }
  6813. });
  6814. }); });
  6815. };
  6816. MultiFactorResolverImpl.prototype.resolveSignIn = function (assertionExtern) {
  6817. return tslib.__awaiter(this, void 0, void 0, function () {
  6818. var assertion;
  6819. return tslib.__generator(this, function (_a) {
  6820. assertion = assertionExtern;
  6821. return [2 /*return*/, this.signInResolver(assertion)];
  6822. });
  6823. });
  6824. };
  6825. return MultiFactorResolverImpl;
  6826. }());
  6827. /**
  6828. * Provides a {@link MultiFactorResolver} suitable for completion of a
  6829. * multi-factor flow.
  6830. *
  6831. * @param auth - The {@link Auth} instance.
  6832. * @param error - The {@link MultiFactorError} raised during a sign-in, or
  6833. * reauthentication operation.
  6834. *
  6835. * @public
  6836. */
  6837. function getMultiFactorResolver(auth, error) {
  6838. var _a;
  6839. var authModular = util.getModularInstance(auth);
  6840. var errorInternal = error;
  6841. _assert(error.customData.operationType, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  6842. _assert((_a = errorInternal.customData._serverResponse) === null || _a === void 0 ? void 0 : _a.mfaPendingCredential, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  6843. return MultiFactorResolverImpl._fromError(authModular, errorInternal);
  6844. }
  6845. /**
  6846. * @license
  6847. * Copyright 2020 Google LLC
  6848. *
  6849. * Licensed under the Apache License, Version 2.0 (the "License");
  6850. * you may not use this file except in compliance with the License.
  6851. * You may obtain a copy of the License at
  6852. *
  6853. * http://www.apache.org/licenses/LICENSE-2.0
  6854. *
  6855. * Unless required by applicable law or agreed to in writing, software
  6856. * distributed under the License is distributed on an "AS IS" BASIS,
  6857. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6858. * See the License for the specific language governing permissions and
  6859. * limitations under the License.
  6860. */
  6861. function withdrawMfa(auth, request) {
  6862. return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:withdraw" /* Endpoint.WITHDRAW_MFA */, _addTidIfNecessary(auth, request));
  6863. }
  6864. var MultiFactorUserImpl = /** @class */ (function () {
  6865. function MultiFactorUserImpl(user) {
  6866. var _this = this;
  6867. this.user = user;
  6868. this.enrolledFactors = [];
  6869. user._onReload(function (userInfo) {
  6870. if (userInfo.mfaInfo) {
  6871. _this.enrolledFactors = userInfo.mfaInfo.map(function (enrollment) {
  6872. return MultiFactorInfoImpl._fromServerResponse(user.auth, enrollment);
  6873. });
  6874. }
  6875. });
  6876. }
  6877. MultiFactorUserImpl._fromUser = function (user) {
  6878. return new MultiFactorUserImpl(user);
  6879. };
  6880. MultiFactorUserImpl.prototype.getSession = function () {
  6881. return tslib.__awaiter(this, void 0, void 0, function () {
  6882. var _a, _b;
  6883. return tslib.__generator(this, function (_c) {
  6884. switch (_c.label) {
  6885. case 0:
  6886. _b = (_a = MultiFactorSessionImpl)._fromIdtoken;
  6887. return [4 /*yield*/, this.user.getIdToken()];
  6888. case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), this.user.auth])];
  6889. }
  6890. });
  6891. });
  6892. };
  6893. MultiFactorUserImpl.prototype.enroll = function (assertionExtern, displayName) {
  6894. return tslib.__awaiter(this, void 0, void 0, function () {
  6895. var assertion, session, finalizeMfaResponse;
  6896. return tslib.__generator(this, function (_a) {
  6897. switch (_a.label) {
  6898. case 0:
  6899. assertion = assertionExtern;
  6900. return [4 /*yield*/, this.getSession()];
  6901. case 1:
  6902. session = (_a.sent());
  6903. return [4 /*yield*/, _logoutIfInvalidated(this.user, assertion._process(this.user.auth, session, displayName))];
  6904. case 2:
  6905. finalizeMfaResponse = _a.sent();
  6906. // New tokens will be issued after enrollment of the new second factors.
  6907. // They need to be updated on the user.
  6908. return [4 /*yield*/, this.user._updateTokensIfNecessary(finalizeMfaResponse)];
  6909. case 3:
  6910. // New tokens will be issued after enrollment of the new second factors.
  6911. // They need to be updated on the user.
  6912. _a.sent();
  6913. // The user needs to be reloaded to get the new multi-factor information
  6914. // from server. USER_RELOADED event will be triggered and `enrolledFactors`
  6915. // will be updated.
  6916. return [2 /*return*/, this.user.reload()];
  6917. }
  6918. });
  6919. });
  6920. };
  6921. MultiFactorUserImpl.prototype.unenroll = function (infoOrUid) {
  6922. return tslib.__awaiter(this, void 0, void 0, function () {
  6923. var mfaEnrollmentId, idToken, idTokenResponse, e_1;
  6924. return tslib.__generator(this, function (_a) {
  6925. switch (_a.label) {
  6926. case 0:
  6927. mfaEnrollmentId = typeof infoOrUid === 'string' ? infoOrUid : infoOrUid.uid;
  6928. return [4 /*yield*/, this.user.getIdToken()];
  6929. case 1:
  6930. idToken = _a.sent();
  6931. return [4 /*yield*/, _logoutIfInvalidated(this.user, withdrawMfa(this.user.auth, {
  6932. idToken: idToken,
  6933. mfaEnrollmentId: mfaEnrollmentId
  6934. }))];
  6935. case 2:
  6936. idTokenResponse = _a.sent();
  6937. // Remove the second factor from the user's list.
  6938. this.enrolledFactors = this.enrolledFactors.filter(function (_a) {
  6939. var uid = _a.uid;
  6940. return uid !== mfaEnrollmentId;
  6941. });
  6942. // Depending on whether the backend decided to revoke the user's session,
  6943. // the tokenResponse may be empty. If the tokens were not updated (and they
  6944. // are now invalid), reloading the user will discover this and invalidate
  6945. // the user's state accordingly.
  6946. return [4 /*yield*/, this.user._updateTokensIfNecessary(idTokenResponse)];
  6947. case 3:
  6948. // Depending on whether the backend decided to revoke the user's session,
  6949. // the tokenResponse may be empty. If the tokens were not updated (and they
  6950. // are now invalid), reloading the user will discover this and invalidate
  6951. // the user's state accordingly.
  6952. _a.sent();
  6953. _a.label = 4;
  6954. case 4:
  6955. _a.trys.push([4, 6, , 7]);
  6956. return [4 /*yield*/, this.user.reload()];
  6957. case 5:
  6958. _a.sent();
  6959. return [3 /*break*/, 7];
  6960. case 6:
  6961. e_1 = _a.sent();
  6962. if ((e_1 === null || e_1 === void 0 ? void 0 : e_1.code) !== "auth/".concat("user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */)) {
  6963. throw e_1;
  6964. }
  6965. return [3 /*break*/, 7];
  6966. case 7: return [2 /*return*/];
  6967. }
  6968. });
  6969. });
  6970. };
  6971. return MultiFactorUserImpl;
  6972. }());
  6973. var multiFactorUserCache = new WeakMap();
  6974. /**
  6975. * The {@link MultiFactorUser} corresponding to the user.
  6976. *
  6977. * @remarks
  6978. * This is used to access all multi-factor properties and operations related to the user.
  6979. *
  6980. * @param user - The user.
  6981. *
  6982. * @public
  6983. */
  6984. function multiFactor(user) {
  6985. var userModular = util.getModularInstance(user);
  6986. if (!multiFactorUserCache.has(userModular)) {
  6987. multiFactorUserCache.set(userModular, MultiFactorUserImpl._fromUser(userModular));
  6988. }
  6989. return multiFactorUserCache.get(userModular);
  6990. }
  6991. var name = "@firebase/auth";
  6992. var version = "0.21.1";
  6993. /**
  6994. * @license
  6995. * Copyright 2020 Google LLC
  6996. *
  6997. * Licensed under the Apache License, Version 2.0 (the "License");
  6998. * you may not use this file except in compliance with the License.
  6999. * You may obtain a copy of the License at
  7000. *
  7001. * http://www.apache.org/licenses/LICENSE-2.0
  7002. *
  7003. * Unless required by applicable law or agreed to in writing, software
  7004. * distributed under the License is distributed on an "AS IS" BASIS,
  7005. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7006. * See the License for the specific language governing permissions and
  7007. * limitations under the License.
  7008. */
  7009. var AuthInterop = /** @class */ (function () {
  7010. function AuthInterop(auth) {
  7011. this.auth = auth;
  7012. this.internalListeners = new Map();
  7013. }
  7014. AuthInterop.prototype.getUid = function () {
  7015. var _a;
  7016. this.assertAuthConfigured();
  7017. return ((_a = this.auth.currentUser) === null || _a === void 0 ? void 0 : _a.uid) || null;
  7018. };
  7019. AuthInterop.prototype.getToken = function (forceRefresh) {
  7020. return tslib.__awaiter(this, void 0, void 0, function () {
  7021. var accessToken;
  7022. return tslib.__generator(this, function (_a) {
  7023. switch (_a.label) {
  7024. case 0:
  7025. this.assertAuthConfigured();
  7026. return [4 /*yield*/, this.auth._initializationPromise];
  7027. case 1:
  7028. _a.sent();
  7029. if (!this.auth.currentUser) {
  7030. return [2 /*return*/, null];
  7031. }
  7032. return [4 /*yield*/, this.auth.currentUser.getIdToken(forceRefresh)];
  7033. case 2:
  7034. accessToken = _a.sent();
  7035. return [2 /*return*/, { accessToken: accessToken }];
  7036. }
  7037. });
  7038. });
  7039. };
  7040. AuthInterop.prototype.addAuthTokenListener = function (listener) {
  7041. this.assertAuthConfigured();
  7042. if (this.internalListeners.has(listener)) {
  7043. return;
  7044. }
  7045. var unsubscribe = this.auth.onIdTokenChanged(function (user) {
  7046. listener((user === null || user === void 0 ? void 0 : user.stsTokenManager.accessToken) || null);
  7047. });
  7048. this.internalListeners.set(listener, unsubscribe);
  7049. this.updateProactiveRefresh();
  7050. };
  7051. AuthInterop.prototype.removeAuthTokenListener = function (listener) {
  7052. this.assertAuthConfigured();
  7053. var unsubscribe = this.internalListeners.get(listener);
  7054. if (!unsubscribe) {
  7055. return;
  7056. }
  7057. this.internalListeners.delete(listener);
  7058. unsubscribe();
  7059. this.updateProactiveRefresh();
  7060. };
  7061. AuthInterop.prototype.assertAuthConfigured = function () {
  7062. _assert(this.auth._initializationPromise, "dependent-sdk-initialized-before-auth" /* AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH */);
  7063. };
  7064. AuthInterop.prototype.updateProactiveRefresh = function () {
  7065. if (this.internalListeners.size > 0) {
  7066. this.auth._startProactiveRefresh();
  7067. }
  7068. else {
  7069. this.auth._stopProactiveRefresh();
  7070. }
  7071. };
  7072. return AuthInterop;
  7073. }());
  7074. /**
  7075. * @license
  7076. * Copyright 2020 Google LLC
  7077. *
  7078. * Licensed under the Apache License, Version 2.0 (the "License");
  7079. * you may not use this file except in compliance with the License.
  7080. * You may obtain a copy of the License at
  7081. *
  7082. * http://www.apache.org/licenses/LICENSE-2.0
  7083. *
  7084. * Unless required by applicable law or agreed to in writing, software
  7085. * distributed under the License is distributed on an "AS IS" BASIS,
  7086. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7087. * See the License for the specific language governing permissions and
  7088. * limitations under the License.
  7089. */
  7090. function getVersionForPlatform(clientPlatform) {
  7091. switch (clientPlatform) {
  7092. case "Node" /* ClientPlatform.NODE */:
  7093. return 'node';
  7094. case "ReactNative" /* ClientPlatform.REACT_NATIVE */:
  7095. return 'rn';
  7096. case "Worker" /* ClientPlatform.WORKER */:
  7097. return 'webworker';
  7098. case "Cordova" /* ClientPlatform.CORDOVA */:
  7099. return 'cordova';
  7100. default:
  7101. return undefined;
  7102. }
  7103. }
  7104. /** @internal */
  7105. function registerAuth(clientPlatform) {
  7106. app._registerComponent(new component.Component("auth" /* _ComponentName.AUTH */, function (container, _a) {
  7107. var deps = _a.options;
  7108. var app = container.getProvider('app').getImmediate();
  7109. var heartbeatServiceProvider = container.getProvider('heartbeat');
  7110. var _b = app.options, apiKey = _b.apiKey, authDomain = _b.authDomain;
  7111. return (function (app, heartbeatServiceProvider) {
  7112. _assert(apiKey && !apiKey.includes(':'), "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */, { appName: app.name });
  7113. // Auth domain is optional if IdP sign in isn't being used
  7114. _assert(!(authDomain === null || authDomain === void 0 ? void 0 : authDomain.includes(':')), "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */, {
  7115. appName: app.name
  7116. });
  7117. var config = {
  7118. apiKey: apiKey,
  7119. authDomain: authDomain,
  7120. clientPlatform: clientPlatform,
  7121. apiHost: "identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */,
  7122. tokenApiHost: "securetoken.googleapis.com" /* DefaultConfig.TOKEN_API_HOST */,
  7123. apiScheme: "https" /* DefaultConfig.API_SCHEME */,
  7124. sdkClientVersion: _getClientVersion(clientPlatform)
  7125. };
  7126. var authInstance = new AuthImpl(app, heartbeatServiceProvider, config);
  7127. _initializeAuthInstance(authInstance, deps);
  7128. return authInstance;
  7129. })(app, heartbeatServiceProvider);
  7130. }, "PUBLIC" /* ComponentType.PUBLIC */)
  7131. /**
  7132. * Auth can only be initialized by explicitly calling getAuth() or initializeAuth()
  7133. * For why we do this, See go/firebase-next-auth-init
  7134. */
  7135. .setInstantiationMode("EXPLICIT" /* InstantiationMode.EXPLICIT */)
  7136. /**
  7137. * Because all firebase products that depend on auth depend on auth-internal directly,
  7138. * we need to initialize auth-internal after auth is initialized to make it available to other firebase products.
  7139. */
  7140. .setInstanceCreatedCallback(function (container, _instanceIdentifier, _instance) {
  7141. var authInternalProvider = container.getProvider("auth-internal" /* _ComponentName.AUTH_INTERNAL */);
  7142. authInternalProvider.initialize();
  7143. }));
  7144. app._registerComponent(new component.Component("auth-internal" /* _ComponentName.AUTH_INTERNAL */, function (container) {
  7145. var auth = _castAuth(container.getProvider("auth" /* _ComponentName.AUTH */).getImmediate());
  7146. return (function (auth) { return new AuthInterop(auth); })(auth);
  7147. }, "PRIVATE" /* ComponentType.PRIVATE */).setInstantiationMode("EXPLICIT" /* InstantiationMode.EXPLICIT */));
  7148. app.registerVersion(name, version, getVersionForPlatform(clientPlatform));
  7149. // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
  7150. app.registerVersion(name, version, 'cjs5');
  7151. }
  7152. /**
  7153. * @license
  7154. * Copyright 2021 Google LLC
  7155. *
  7156. * Licensed under the Apache License, Version 2.0 (the "License");
  7157. * you may not use this file except in compliance with the License.
  7158. * You may obtain a copy of the License at
  7159. *
  7160. * http://www.apache.org/licenses/LICENSE-2.0
  7161. *
  7162. * Unless required by applicable law or agreed to in writing, software
  7163. * distributed under the License is distributed on an "AS IS" BASIS,
  7164. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7165. * See the License for the specific language governing permissions and
  7166. * limitations under the License.
  7167. */
  7168. // Initialize the fetch polyfill, the types are slightly off so just cast and hope for the best
  7169. FetchProvider.initialize(fetchImpl__namespace.default, fetchImpl__namespace.Headers, fetchImpl__namespace.Response);
  7170. // First, we set up the various platform-specific features for Node (register
  7171. // the version and declare the Node getAuth function)
  7172. function getAuth(app$1) {
  7173. if (app$1 === void 0) { app$1 = app.getApp(); }
  7174. var provider = app._getProvider(app$1, 'auth');
  7175. if (provider.isInitialized()) {
  7176. return provider.getImmediate();
  7177. }
  7178. var auth = initializeAuth(app$1);
  7179. var authEmulatorHost = util.getDefaultEmulatorHost('auth');
  7180. if (authEmulatorHost) {
  7181. connectAuthEmulator(auth, "http://".concat(authEmulatorHost));
  7182. }
  7183. return auth;
  7184. }
  7185. registerAuth("Node" /* ClientPlatform.NODE */);
  7186. // The rest of this file contains no-ops and errors for browser-specific
  7187. // methods. We keep the browser and Node entry points the same, but features
  7188. // that only work in browsers are set to either do nothing (setPersistence) or
  7189. // to reject with an auth/operation-not-supported-in-this-environment error.
  7190. // The below exports are pulled into the main entry point by a rollup alias
  7191. // plugin (overwriting the default browser imports).
  7192. /** auth/operation-not-supported-in-this-environment */
  7193. var NOT_AVAILABLE_ERROR = _createError("operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
  7194. /** Reject with auth/operation-not-supported-in-this-environment */
  7195. function fail() {
  7196. return tslib.__awaiter(this, void 0, void 0, function () {
  7197. return tslib.__generator(this, function (_a) {
  7198. throw NOT_AVAILABLE_ERROR;
  7199. });
  7200. });
  7201. }
  7202. /**
  7203. * A class which will throw with
  7204. * auth/operation-not-supported-in-this-environment if instantiated
  7205. */
  7206. var FailClass = /** @class */ (function () {
  7207. function FailClass() {
  7208. throw NOT_AVAILABLE_ERROR;
  7209. }
  7210. return FailClass;
  7211. }());
  7212. var browserLocalPersistence = inMemoryPersistence;
  7213. var browserSessionPersistence = inMemoryPersistence;
  7214. var indexedDBLocalPersistence = inMemoryPersistence;
  7215. var browserPopupRedirectResolver = NOT_AVAILABLE_ERROR;
  7216. var PhoneAuthProvider = FailClass;
  7217. var signInWithPhoneNumber = fail;
  7218. var linkWithPhoneNumber = fail;
  7219. var reauthenticateWithPhoneNumber = fail;
  7220. var updatePhoneNumber = fail;
  7221. var signInWithPopup = fail;
  7222. var linkWithPopup = fail;
  7223. var reauthenticateWithPopup = fail;
  7224. var signInWithRedirect = fail;
  7225. var linkWithRedirect = fail;
  7226. var reauthenticateWithRedirect = fail;
  7227. var getRedirectResult = fail;
  7228. var RecaptchaVerifier = FailClass;
  7229. var PhoneMultiFactorGenerator = /** @class */ (function () {
  7230. function PhoneMultiFactorGenerator() {
  7231. }
  7232. PhoneMultiFactorGenerator.assertion = function () {
  7233. throw NOT_AVAILABLE_ERROR;
  7234. };
  7235. return PhoneMultiFactorGenerator;
  7236. }());
  7237. // Set persistence should no-op instead of fail. Changing the prototype will
  7238. // make sure both setPersistence(auth, persistence) and
  7239. // auth.setPersistence(persistence) are covered.
  7240. AuthImpl.prototype.setPersistence = function () { return tslib.__awaiter(void 0, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
  7241. return [2 /*return*/];
  7242. }); }); };
  7243. exports.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
  7244. exports.ActionCodeOperation = ActionCodeOperation;
  7245. exports.ActionCodeURL = ActionCodeURL;
  7246. exports.AuthCredential = AuthCredential;
  7247. exports.AuthImpl = AuthImpl;
  7248. exports.BaseOAuthProvider = BaseOAuthProvider;
  7249. exports.EmailAuthCredential = EmailAuthCredential;
  7250. exports.EmailAuthProvider = EmailAuthProvider;
  7251. exports.FacebookAuthProvider = FacebookAuthProvider;
  7252. exports.FactorId = FactorId;
  7253. exports.FederatedAuthProvider = FederatedAuthProvider;
  7254. exports.FetchProvider = FetchProvider;
  7255. exports.GithubAuthProvider = GithubAuthProvider;
  7256. exports.GoogleAuthProvider = GoogleAuthProvider;
  7257. exports.OAuthCredential = OAuthCredential;
  7258. exports.OAuthProvider = OAuthProvider;
  7259. exports.OperationType = OperationType;
  7260. exports.PhoneAuthCredential = PhoneAuthCredential;
  7261. exports.PhoneAuthProvider = PhoneAuthProvider;
  7262. exports.PhoneMultiFactorGenerator = PhoneMultiFactorGenerator;
  7263. exports.ProviderId = ProviderId;
  7264. exports.RecaptchaVerifier = RecaptchaVerifier;
  7265. exports.SAMLAuthCredential = SAMLAuthCredential;
  7266. exports.SAMLAuthProvider = SAMLAuthProvider;
  7267. exports.SignInMethod = SignInMethod;
  7268. exports.TwitterAuthProvider = TwitterAuthProvider;
  7269. exports.UserImpl = UserImpl;
  7270. exports._assert = _assert;
  7271. exports._castAuth = _castAuth;
  7272. exports._createError = _createError;
  7273. exports._emulatorUrl = _emulatorUrl;
  7274. exports._fail = _fail;
  7275. exports._getClientVersion = _getClientVersion;
  7276. exports._getInstance = _getInstance;
  7277. exports._isAndroid = _isAndroid;
  7278. exports._isIE10 = _isIE10;
  7279. exports._isIOS = _isIOS;
  7280. exports._isIOS7Or8 = _isIOS7Or8;
  7281. exports._isIframe = _isIframe;
  7282. exports._isMobileBrowser = _isMobileBrowser;
  7283. exports._isSafari = _isSafari;
  7284. exports._link = _link;
  7285. exports._performApiRequest = _performApiRequest;
  7286. exports._persistenceKeyName = _persistenceKeyName;
  7287. exports._reauthenticate = _reauthenticate;
  7288. exports._signInWithCredential = _signInWithCredential;
  7289. exports.applyActionCode = applyActionCode;
  7290. exports.beforeAuthStateChanged = beforeAuthStateChanged;
  7291. exports.browserLocalPersistence = browserLocalPersistence;
  7292. exports.browserPopupRedirectResolver = browserPopupRedirectResolver;
  7293. exports.browserSessionPersistence = browserSessionPersistence;
  7294. exports.checkActionCode = checkActionCode;
  7295. exports.confirmPasswordReset = confirmPasswordReset;
  7296. exports.connectAuthEmulator = connectAuthEmulator;
  7297. exports.createUserWithEmailAndPassword = createUserWithEmailAndPassword;
  7298. exports.debugAssert = debugAssert;
  7299. exports.debugErrorMap = debugErrorMap;
  7300. exports.deleteUser = deleteUser;
  7301. exports.fetchSignInMethodsForEmail = fetchSignInMethodsForEmail;
  7302. exports.getAdditionalUserInfo = getAdditionalUserInfo;
  7303. exports.getAuth = getAuth;
  7304. exports.getIdToken = getIdToken;
  7305. exports.getIdTokenResult = getIdTokenResult;
  7306. exports.getMultiFactorResolver = getMultiFactorResolver;
  7307. exports.getRedirectResult = getRedirectResult;
  7308. exports.inMemoryPersistence = inMemoryPersistence;
  7309. exports.indexedDBLocalPersistence = indexedDBLocalPersistence;
  7310. exports.initializeAuth = initializeAuth;
  7311. exports.isSignInWithEmailLink = isSignInWithEmailLink;
  7312. exports.linkWithCredential = linkWithCredential;
  7313. exports.linkWithPhoneNumber = linkWithPhoneNumber;
  7314. exports.linkWithPopup = linkWithPopup;
  7315. exports.linkWithRedirect = linkWithRedirect;
  7316. exports.multiFactor = multiFactor;
  7317. exports.onAuthStateChanged = onAuthStateChanged;
  7318. exports.onIdTokenChanged = onIdTokenChanged;
  7319. exports.parseActionCodeURL = parseActionCodeURL;
  7320. exports.prodErrorMap = prodErrorMap;
  7321. exports.reauthenticateWithCredential = reauthenticateWithCredential;
  7322. exports.reauthenticateWithPhoneNumber = reauthenticateWithPhoneNumber;
  7323. exports.reauthenticateWithPopup = reauthenticateWithPopup;
  7324. exports.reauthenticateWithRedirect = reauthenticateWithRedirect;
  7325. exports.reload = reload;
  7326. exports.sendEmailVerification = sendEmailVerification;
  7327. exports.sendPasswordResetEmail = sendPasswordResetEmail;
  7328. exports.sendSignInLinkToEmail = sendSignInLinkToEmail;
  7329. exports.setPersistence = setPersistence;
  7330. exports.signInAnonymously = signInAnonymously;
  7331. exports.signInWithCredential = signInWithCredential;
  7332. exports.signInWithCustomToken = signInWithCustomToken;
  7333. exports.signInWithEmailAndPassword = signInWithEmailAndPassword;
  7334. exports.signInWithEmailLink = signInWithEmailLink;
  7335. exports.signInWithIdp = signInWithIdp;
  7336. exports.signInWithPhoneNumber = signInWithPhoneNumber;
  7337. exports.signInWithPopup = signInWithPopup;
  7338. exports.signInWithRedirect = signInWithRedirect;
  7339. exports.signOut = signOut;
  7340. exports.unlink = unlink;
  7341. exports.updateCurrentUser = updateCurrentUser;
  7342. exports.updateEmail = updateEmail;
  7343. exports.updatePassword = updatePassword;
  7344. exports.updatePhoneNumber = updatePhoneNumber;
  7345. exports.updateProfile = updateProfile;
  7346. exports.useDeviceLanguage = useDeviceLanguage;
  7347. exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
  7348. exports.verifyPasswordResetCode = verifyPasswordResetCode;
  7349. //# sourceMappingURL=index-69e083b1.js.map