next-firebase-auth
Version:
Simple Firebase authentication for all Next.js rendering strategies
2 lines • 42.4 kB
JavaScript
/*! For license information please see index.node.js.LICENSE.txt */
(()=>{"use strict";var e={369:(e,t,n)=>{var r=n(352)("cookies"),i=n(815),o=n(685),s={},a=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,u=/^(?:lax|none|strict)$/i;function c(e,t,n){if(!(this instanceof c))return new c(e,t,n);this.secure=void 0,this.request=e,this.response=t,n&&(Array.isArray(n)?(r('"keys" argument; provide using options {"keys": [...]}'),this.keys=new i(n)):n.constructor&&"Keygrip"===n.constructor.name?(r('"keys" argument; provide using options {"keys": keygrip}'),this.keys=n):(this.keys=Array.isArray(n.keys)?new i(n.keys):n.keys,this.secure=n.secure))}function l(e,t,n){if(!a.test(e))throw new TypeError("argument name is invalid");if(t&&!a.test(t))throw new TypeError("argument value is invalid");for(var e in this.name=e,this.value=t||"",n)this[e]=n[e];if(this.value||(this.expires=new Date(0),this.maxAge=null),this.path&&!a.test(this.path))throw new TypeError("option path is invalid");if(this.domain&&!a.test(this.domain))throw new TypeError("option domain is invalid");if(this.sameSite&&!0!==this.sameSite&&!u.test(this.sameSite))throw new TypeError("option sameSite is invalid")}function f(e,t){if(t.overwrite)for(var n=e.length-1;n>=0;n--)0===e[n].indexOf(t.name+"=")&&e.splice(n,1);e.push(t.toHeader())}c.prototype.get=function(e,t){var n,r,i,o,a,u,c=e+".sig",l=t&&void 0!==t.signed?t.signed:!!this.keys;if((n=this.request.headers.cookie)&&(r=n.match(function(e){return s[e]?s[e]:s[e]=new RegExp("(?:^|;) *"+e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")+"=([^;]*)")}(e)),r)){if(i=r[1],!t||!l)return i;if(o=this.get(c)){if(a=e+"="+i,!this.keys)throw new Error(".keys required for signed cookies");if(!((u=this.keys.index(a,o))<0))return u&&this.set(c,this.keys.sign(a),{signed:!1}),i;this.set(c,null,{path:"/",signed:!1})}}},c.prototype.set=function(e,t,n){var i=this.response,s=this.request,a=i.getHeader("Set-Cookie")||[],u=void 0!==this.secure?!!this.secure:"https"===s.protocol||s.connection.encrypted,c=new l(e,t,n),h=n&&void 0!==n.signed?n.signed:!!this.keys;if("string"==typeof a&&(a=[a]),!u&&n&&n.secure)throw new Error("Cannot send secure cookie over unencrypted connection");if(c.secure=n&&void 0!==n.secure?n.secure:u,n&&"secureProxy"in n&&(r('"secureProxy" option; use "secure" option, provide "secure" to constructor if needed'),c.secure=n.secureProxy),f(a,c),n&&h){if(!this.keys)throw new Error(".keys required for signed cookies");c.value=this.keys.sign(c.toString()),c.name+=".sig",f(a,c)}return(i.set?o.OutgoingMessage.prototype.setHeader:i.setHeader).call(i,"Set-Cookie",a),this},l.prototype.path="/",l.prototype.expires=void 0,l.prototype.domain=void 0,l.prototype.httpOnly=!0,l.prototype.sameSite=!1,l.prototype.secure=!1,l.prototype.overwrite=!1,l.prototype.toString=function(){return this.name+"="+this.value},l.prototype.toHeader=function(){var e=this.toString();return this.maxAge&&(this.expires=new Date(Date.now()+this.maxAge)),this.path&&(e+="; path="+this.path),this.expires&&(e+="; expires="+this.expires.toUTCString()),this.domain&&(e+="; domain="+this.domain),this.sameSite&&(e+="; samesite="+(!0===this.sameSite?"strict":this.sameSite.toLowerCase())),this.secure&&(e+="; secure"),this.httpOnly&&(e+="; httponly"),e},Object.defineProperty(l.prototype,"maxage",{configurable:!0,enumerable:!0,get:function(){return this.maxAge},set:function(e){return this.maxAge=e}}),r.property(l.prototype,"maxage",'"maxage"; use "maxAge" instead'),c.connect=c.express=function(e){return function(t,n,r){t.cookies=n.cookies=new c(t,n,{keys:e}),r()}},c.Cookie=l,e.exports=c},281:(e,t,n)=>{var r=n(469),i={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},s={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},a={};function u(e){return r.isMemo(e)?s:a[e.$$typeof]||i}a[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},a[r.Memo]=s;var c=Object.defineProperty,l=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,h=Object.getOwnPropertyDescriptor,d=Object.getPrototypeOf,p=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(p){var i=d(n);i&&i!==p&&e(t,i,r)}var s=l(n);f&&(s=s.concat(f(n)));for(var a=u(t),v=u(n),g=0;g<s.length;++g){var y=s[g];if(!(o[y]||r&&r[y]||v&&v[y]||a&&a[y])){var b=h(n,y);try{c(t,y,b)}catch(e){}}}}return t}},718:(e,t,n)=>{var r;n.d(t,{g:()=>r}),function(e){e.RENDER="render",e.SHOW_LOADER="showLoader",e.RETURN_NULL="returnNull",e.REDIRECT_TO_LOGIN="redirectToLogin",e.REDIRECT_TO_APP="redirectToApp"}(r||(r={}))},728:(e,t,n)=>{n.d(t,{Mb:()=>a,P0:()=>o,gY:()=>u,sN:()=>s});var r=n(795),i=function(){return(0,r.i)().cookies.name},o=function(){var e=i();return"".concat(e,".AuthUser")},s=function(){return"".concat(o(),".sig")},a=function(){var e=i();return"".concat(e,".AuthUserTokens")},u=function(){return"".concat(a(),".sig")}},974:(e,t,n)=>{n.d(t,{Y:()=>i});var r=["aud","auth_time","email","email_verified","exp","firebase","iat","iss","name","phone_number","picture","sub","uid","user_id"],i=function(e){void 0===e&&(e={});var t={};return Object.keys(e).forEach((function(n){r.includes(n)||(t[n]=e[n])})),t}},795:(e,t,n)=>{n.d(t,{i:()=>l,v:()=>c});var r,i=n(245),o=n(163),s={debug:!1,onVerifyTokenError:function(e){},onTokenRefreshError:function(e){},cookies:{httpOnly:!0,maxAge:6048e5,overwrite:!0,path:"/",sameSite:"strict",secure:!0,signed:!0}},a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)},u=12096e5,c=function(e){var t;(0,o.Z)("[init] Setting config with provided value:",a(a(a({},t=e),{cookies:a(a({},t.cookies),{keys:["hidden"]})}),t.firebaseAdminInitConfig&&{firebaseAdminInitConfig:a(a({},t.firebaseAdminInitConfig),t.firebaseAdminInitConfig.credential&&{credential:a(a({},t.firebaseAdminInitConfig.credential),{privateKey:"hidden",clientEmail:"hidden"})})}));var n=e.cookies,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["cookies"]),l=a(a(a({},s),c),{cookies:a(a({},s.cookies),n||{})}),f=function(e){var t=[];e.tokenChangedHandler&&(e.loginAPIEndpoint&&t.push('The "loginAPIEndpoint" setting should not be set if you are using a "tokenChangedHandler".'),e.logoutAPIEndpoint&&t.push('The "logoutAPIEndpoint" setting should not be set if you are using a "tokenChangedHandler".'),e.onLoginRequestError&&t.push('The "onLoginRequestError" setting should not be set if you are using a "tokenChangedHandler".'),e.onLogoutRequestError&&t.push('The "onLogoutRequestError" setting should not be set if you are using a "tokenChangedHandler".')),e.firebaseClientInitConfig&&e.firebaseClientInitConfig.apiKey||t.push('The "firebaseClientInitConfig.apiKey" value is required.'),e.firebaseAuthEmulatorHost&&e.firebaseAuthEmulatorHost.startsWith("http")&&t.push("The firebaseAuthEmulatorHost should be set without a prefix (e.g., localhost:9099)");var n=["function","undefined"];n.indexOf(typeof e.onVerifyTokenError)<0&&t.push('Invalid next-firebase-auth options: The "onVerifyTokenError" setting must be a function.'),n.indexOf(typeof e.onTokenRefreshError)<0&&t.push('Invalid next-firebase-auth options: The "onTokenRefreshError" setting must be a function.'),n.indexOf(typeof e.onLoginRequestError)<0&&t.push('Invalid next-firebase-auth options: The "onLoginRequestError" setting must be a function.'),n.indexOf(typeof e.onLogoutRequestError)<0&&t.push('Invalid next-firebase-auth options: The "onLogoutRequestError" setting must be a function.');var r=e.cookies.keys,o=Array.isArray(r)?r.length&&(!r.filter||r.filter((function(e){return void 0!==e})).length):!!r;return(0,i.Z)()?(e.tokenChangedHandler||(e.loginAPIEndpoint||t.push('The "loginAPIEndpoint" setting is required.'),e.logoutAPIEndpoint||t.push('The "logoutAPIEndpoint" setting is required.')),e.firebaseAdminInitConfig&&e.firebaseAdminInitConfig.credential&&e.firebaseAdminInitConfig.credential.privateKey&&t.push('The "firebaseAdminInitConfig" private key setting should not be available on the client side.'),o&&t.push('The "cookies.keys" setting should not be available on the client side.')):(e.cookies.name||t.push('The "cookies.name" setting is required on the server side.'),e.firebaseAuthEmulatorHost&&(process.env.FIREBASE_AUTH_EMULATOR_HOST?process.env.FIREBASE_AUTH_EMULATOR_HOST!==e.firebaseAuthEmulatorHost&&t.push('The "FIREBASE_AUTH_EMULATOR_HOST" environment variable should be the same as the host set in the config'):t.push('The "FIREBASE_AUTH_EMULATOR_HOST" environment variable should be set if you are using the "firebaseAuthEmulatorHost" option')),(!e.cookies.maxAge||e.cookies.maxAge>u)&&t.push('The "cookies.maxAge" setting must be less than two weeks ('.concat(u," ms)."))),{isValid:0===t.length,errors:t}}(l),h=f.isValid,d=f.errors;if(!h)throw new Error("Invalid next-firebase-auth options: ".concat(d.join(" ")));r=l},l=function(){if(!r)throw new Error("next-firebase-auth must be initialized before rendering.");return r}},681:(e,t,n)=>{n.d(t,{kT:()=>u,ej:()=>s,d8:()=>a});var r=n(369),i=n.n(r),o=function(e,t){var n=e.req,r=e.res,o=void 0===t?{}:t,s=o.keys,a=o.secure;return i()(n,r,{keys:s,secure:a})},s=function(e,t,n){var r=t.req,i=t.res,s=void 0===i?{getHeader:function(){return[]},setHeader:function(){return{call:function(){}}}}:i,a=void 0===n?{}:n,u=a.keys,c=a.secure,l=a.signed,f=void 0!==l&&l;if(f&&!(Array.isArray(u)?u.length&&(!u.filter||u.filter((function(e){return void 0!==e})).length):u))throw new Error('The "keys" value must be provided when using signed cookies.');if(!r)throw new Error('The "req" argument is required when calling `getCookie`.');var h,d,p=o({req:r,res:s},{keys:u,secure:c}).get(e,{signed:f});return p?(h=p,d=Buffer.from(h,"base64").toString("utf8"),JSON.parse(d)):void 0},a=function(e,t,n,r){var i=n.req,s=n.res,a=void 0===r?{}:r,u=a.keys,c=a.domain,l=a.httpOnly,f=a.maxAge,h=a.overwrite,d=a.path,p=a.sameSite,v=a.secure,g=a.signed;if(g&&!u)throw new Error('The "keys" value must be provided when using signed cookies.');if(!s)throw new Error('The "res" argument is required when calling `setCookie`.');var y,b,m=o({req:i,res:s},{keys:u,secure:v}),w=null==t?void 0:(y=t,b=JSON.stringify(y),Buffer.from(b).toString("base64"));m.set(e,w,{domain:c,httpOnly:l,maxAge:f,overwrite:h,path:d,sameSite:p,secure:v,signed:g})},u=function(e,t,n){a(e,void 0,t,n)}},63:(e,t,n)=>{n.d(t,{Z:()=>c});var r=n(245),i=n(974),o=n(795),s=function(){return s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},s.apply(this,arguments)},a=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},u=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};const c=function(e){var t=void 0===e?{}:e,c=t.firebaseUserClientSDK,l=t.firebaseUserAdminSDK,f=t.serializedUser,h=t.clientInitialized,d=void 0!==h&&h,p=t.token,v=void 0===p?null:p,g=t.claims;if([c,l,f].reduce((function(e,t){return t?e+1:e}),0)>1)throw new Error('createUser cannot receive more than one of the following properties: "firebaseUserClientSDK", "firebaseUserAdminSDK", "serializedUser"');if(d&&(l||f))throw new Error('The "clientInitialized" value can only be true when called with the "firebaseUserClientSDK" property or no user.');if(g&&(l||f))throw new Error('The "claims" value can only be set in conjunction with the "firebaseUserClientSDK" property.');if(v&&!l)throw new Error('The "token" value can only be set if the "firebaseUserAdminSDK" property is defined.');var y={},b=null,m=null,w=!1,k=null,T=null,E=null,x=null,S=function(){return a(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,null]}))}))},O=function(){return a(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2]}))}))},A=null;if(c){if((0,r.Z)()){var R=n(324).getApp,C=n(610),I=C.getAuth,U=C.signOut,P=(0,o.i)().firebaseClientAppName;O=function(){return a(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,U(I(R(P)))]}))}))}}y=(0,i.Y)(g),b=c.uid,m=c.email,w=c.emailVerified,T=c.phoneNumber,E=c.displayName,x=c.photoURL,k=c.tenantId,S=function(e){return a(void 0,void 0,void 0,(function(){return u(this,(function(t){return[2,c.getIdToken(e)]}))}))},A=null}else if(l)y=(0,i.Y)(l),b=l.uid,m=l.email||null,w=l.email_verified||!1,T=l.phone_number||null,E=l.name,k=l.firebase&&l.firebase.tenant||null,x=l.picture||null,S=function(){return a(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,v]}))}))},A=v;else if(f){var Z=JSON.parse(f);y=Z.claims||{},b=Z.id||null,m=Z.email||null,w=Z.emailVerified,k=Z.tenantId||null,T=Z.phoneNumber||null,E=Z.displayName||null,x=Z.photoURL||null,S=function(){return a(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,Z._token||null]}))}))},A=Z._token||null}return{id:b,email:m,emailVerified:w,tenantId:k,phoneNumber:T,displayName:E,photoURL:x,claims:y,getIdToken:S,clientInitialized:d,firebaseUser:c||null,signOut:O,serialize:function(e){var t=(void 0===e?{}:e).includeToken,n=void 0===t||t;return JSON.stringify(s({id:b,claims:y,email:m,emailVerified:w,tenantId:k,phoneNumber:T,displayName:E,photoURL:x,clientInitialized:d},n&&{_token:A}))}}}},157:(e,t,n)=>{n.d(t,{_:()=>y,y:()=>g});const r=require("firebase-admin/auth");var i=n(144),o=n(63),s=n(795),a=n(163),u=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},c=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},l=function(){return process.env.FIREBASE_AUTH_EMULATOR_HOST?"http://".concat(process.env.FIREBASE_AUTH_EMULATOR_HOST,"/"):"https://"},f=function(){return(0,s.i)().firebaseClientInitConfig.apiKey},h=function(e){return"[verifyIdToken] Error verifying the ID token: ".concat(e,". The user will be unauthenticated.")},d=function(){if("undefined"==typeof fetch)throw new Error("A `fetch` global is required when using next-firebase-auth. See documentation on setting up a `fetch` polyfill.")},p=function(e){return e?(0,r.getAuth)().tenantManager().authForTenant(e):(0,r.getAuth)()},v=function(e){return u(void 0,void 0,void 0,(function(){var t,n,r,i;return c(this,(function(o){switch(o.label){case 0:if(!e)throw new Error('The "refreshToken" argument is required.');return t=f(),n="".concat(l(),"securetoken.googleapis.com/v1/token?key=").concat(t),[4,fetch(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=refresh_token&refresh_token=".concat(e)})];case 1:return[4,(r=o.sent()).json()];case 2:if(i=o.sent(),!r.ok)throw new Error("Problem refreshing token: ".concat(JSON.stringify(i)));return[2,i.id_token]}}))}))},g=function(e,t){return u(void 0,void 0,void 0,(function(){var n,r,u,l,f,g,y,b,m,w,k,T,E,x;return c(this,(function(c){switch(c.label){case 0:d(),(0,i.Z)(),r=e,u=(0,s.i)(),l=u.onTokenRefreshError,f=u.onVerifyTokenError,g=u.tenantId,y=p(g),c.label=1;case 1:return c.trys.push([1,3,,28]),[4,y.verifyIdToken(e)];case 2:return n=c.sent(),[3,28];case 3:if(b=c.sent(),!(m=b).code)return[3,26];switch(m.code){case"auth/invalid-user-token":case"auth/user-token-expired":case"auth/user-disabled":return[3,4];case"auth/id-token-expired":case"auth/argument-error":return[3,5]}return[3,22];case 4:return r=null,n=void 0,(0,a.Z)(h(m.code)),[3,25];case 5:if(!t)return[3,22];(0,a.Z)("[verifyIdToken] The ID token is expired (error code ".concat(m.code,"). Attempting to refresh the ID token.")),w=!1,c.label=6;case 6:return c.trys.push([6,8,,13]),[4,v(t)];case 7:return r=c.sent(),[3,13];case 8:return k=c.sent(),w=!0,k instanceof Error?l?[4,l(k)]:[3,10]:[3,11];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:(0,a.Z)(k),c.label=12;case 12:return[3,13];case 13:if(w)return[3,21];(0,a.Z)("[verifyIdToken] Successfully refreshed the ID token."),c.label=14;case 14:return c.trys.push([14,16,,21]),[4,y.verifyIdToken(r)];case 15:return n=c.sent(),[3,21];case 16:return(T=c.sent())instanceof Error?f?[4,f(T)]:[3,18]:[3,19];case 17:c.sent(),c.label=18;case 18:return(E=T).code&&(0,a.Z)(h(E.code)),[3,20];case 19:(0,a.Z)(T),c.label=20;case 20:return w=!0,[3,21];case 21:return w&&(r=null,n=void 0,(0,a.Z)("[verifyIdToken] Failed to refresh the ID token. The user will be unauthenticated.")),[3,25];case 22:return r=null,n=void 0,f?[4,f(m)]:[3,24];case 23:c.sent(),c.label=24;case 24:(0,a.Z)(h(m.code)),c.label=25;case 25:return[3,27];case 26:r=null,n=void 0,(0,a.Z)(b),c.label=27;case 27:return[3,28];case 28:return(x=(0,o.Z)({firebaseUserAdminSDK:n,token:r})).id&&(0,a.Z)("[verifyIdToken] Successfully verified the ID token. The user is authenticated."),[2,x]}}))}))},y=function(e){return u(void 0,void 0,void 0,(function(){var t,n,r,o,s,u,h,v,y,b;return c(this,(function(c){switch(c.label){case 0:return d(),(0,i.Z)(),[4,g(e)];case 1:if(t=c.sent(),n=p(t.tenantId),!t.id)throw new Error("Failed to verify the ID token.");return(0,a.Z)("[setAuthCookies] Getting the Firebase user record."),[4,n.getUser(t.id).catch((function(){return(0,a.Z)("[setAuthCookies] Failed to get the Firebase user record."),{customClaims:{}}}))];case 2:return r=c.sent().customClaims,(0,a.Z)("[setAuthCookies] Getting a refresh token from the ID token."),[4,n.createCustomToken(t.id,r)];case 3:return o=c.sent(),s=f(),u="".concat(l(),"identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=").concat(s),[4,fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:o,returnSecureToken:!0})})];case 4:return[4,(h=c.sent()).json()];case 5:if(v=c.sent(),!h.ok)throw(0,a.Z)("[setAuthCookies] Failed to get a refresh token from the ID token."),new Error("Problem getting a refresh token: ".concat(JSON.stringify(v)));return y=v.idToken,b=v.refreshToken,[2,{idToken:y,refreshToken:b,user:t}]}}))}))}},951:(e,t,n)=>{n.d(t,{Z:()=>l});var r=n(63),i=n(681),o=n(157),s=n(728),a=n(795),u=n(163),c=n(144);const l=function(e){var t,n,l,f,h=e.req,d=e.includeToken,p=void 0===d||d,v=e.authCookieValue,g=e.authCookieSigValue;return t=void 0,n=void 0,f=function(){var e,t,n,l,f,d,y,b,m,w,k,T,E,x;return function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(S){switch(S.label){case 0:if(e=(0,a.i)().cookies,t=e.keys,n=e.secure,l=e.signed,(0,c.Z)(),d=h,!h){if(!v)throw new Error('Either "req" or "authCookieValue" must be provided.');y=p?(0,s.Mb)():(0,s.P0)(),b=p?(0,s.gY)():(0,s.sN)(),m=g?"".concat(b,"=").concat(g,";"):"",w="".concat(y,"=").concat(v,";").concat(g?" ".concat(m):""),d={headers:{cookie:w}}}if(!d)throw new Error('When "authCookieValue" is not provided, "req" must be defined.');return p?((0,u.Z)("[getUserFromCookies] Attempting to get user info from cookies via the ID token."),x=(0,i.ej)((0,s.Mb)(),{req:d},{keys:t,secure:n,signed:l}),k=x?JSON.parse(x):{},T=k.idToken,E=k.refreshToken,T?((0,u.Z)("[getUserFromCookies] Successfully retrieved the ID token from cookies."),[4,(0,o.y)(T,E)]):[3,2]):[3,4];case 1:return f=S.sent(),[3,3];case 2:(0,u.Z)("[getUserFromCookies] Failed to retrieve the ID token from cookies. This will happen if the user is not logged in, the provided cookie values are invalid, or the cookie values don't align with your cookie settings. The user will be unauthenticated."),f=(0,r.Z)(),S.label=3;case 3:return[3,5];case 4:if(!l)throw new Error("Cookies must be signed when using withUserSSR.");(0,u.Z)("[getUserFromCookies] Attempting to get user info from cookies (not using the ID token)."),(x=(0,i.ej)((0,s.P0)(),{req:d},{keys:t,secure:n,signed:l}))?(0,u.Z)("[getUserFromCookies] Successfully retrieved the user info from cookies."):(0,u.Z)("[getUserFromCookies] Failed to retrieve the user info from cookies. The provided cookie values might be invalid or not align with your cookie settings. The user will be unauthenticated."),f=(0,r.Z)({serializedUser:x}),S.label=5;case 5:return[2,f]}}))},new((l=void 0)||(l=Promise))((function(e,r){function i(e){try{s(f.next(e))}catch(e){r(e)}}function o(e){try{s(f.throw(e))}catch(e){r(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof l?n:new l((function(e){e(n)}))).then(i,o)}s((f=f.apply(t,n||[])).next())}))}},144:(e,t,n)=>{n.d(t,{Z:()=>a});const r=require("firebase-admin/app");var i=n(795),o=n(163),s=function(){return s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},s.apply(this,arguments)};const a=function(){if(!(0,r.getApps)().length){var e=(0,i.i)(),t=e.firebaseAdminInitConfig,n=e.useFirebaseAdminDefaultCredential;if(!t&&!n)throw new Error('Missing firebase-admin credentials in next-firebase-auth. Set "firebaseAdminInitConfig", "useFirebaseAdminDefaultCredential", or initialize firebase-admin yourself.');(0,r.initializeApp)(s(s({},t),{credential:n?(0,r.applicationDefault)():(0,r.cert)(s({},null==t?void 0:t.credential))})),(0,o.Z)("[init] Initialized the Firebase admin SDK.")}}},245:(e,t,n)=>{n.d(t,{Z:()=>r});const r=function(){return"undefined"!=typeof window}},163:(e,t,n)=>{n.d(t,{Z:()=>a,y:()=>s});var r=n(245),i=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))},o=!1,s=function(e){o=e};const a=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(o){var n=(0,r.Z)()?["%cnext-firebase-auth","background: #ffa000; color: #fff; border-radius: 2px; padding: 2px 6px"]:["next-firebase-auth:"];console.log.apply(console,i(i([],n,!1),e,!1))}}},739:(e,t,n)=>{n.d(t,{U:()=>a,j:()=>u});var r=n(795),i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)},o=function(e){var t=e.ctx,n=e.user,r=e.redirectDestination;if("function"==typeof r){var s=r({ctx:t,user:n});return o({ctx:t,user:n,redirectDestination:s})}return"string"==typeof r?{destination:r,permanent:!1}:"object"==typeof r?i({permanent:!1},r):void 0},s=function(e){var t=e.redirectConfigName,n=e.redirectURL,i=e.ctx,s=e.user,a=n||(0,r.i)()[t];return function(e,t){if(!t||"string"!=typeof t&&!("destination"in t))throw new Error('The "'.concat(e,'" must be set to a non-empty string, an object literal containing "destination", or a function that returns either.'));return t}(t,o({ctx:i,user:s,redirectDestination:a}))},a=function(e){var t=e.redirectURL,n=e.user,r=e.ctx;return s({redirectConfigName:"authPageURL",redirectURL:t,user:n,ctx:r})},u=function(e){var t=e.redirectURL,n=e.user,r=e.ctx;return s({redirectConfigName:"appPageURL",redirectURL:t,user:n,ctx:r})}},355:(e,t,n)=>{n.d(t,{S:()=>i,Z:()=>o});var r=n(689),i=(0,r.createContext)(void 0);const o=function(){var e=(0,r.useContext)(i);if(!e)throw new Error("When using `useUser`, the page must be wrapped in `withUser`.");return e}},85:(e,t,n)=>{n.d(t,{Z:()=>T});var r=n(281),i=n.n(r),o=n(63),s=n(689),a=n(324),u=n(610),c=n(795),l=n(974),f=n(163),h=function(){return h=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},h.apply(this,arguments)},d=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},p=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},v=function(e){return d(void 0,void 0,void 0,(function(){var t,n,r,i,o,s,a,u,l,h;return p(this,(function(d){switch(d.label){case 0:return t=(0,c.i)(),n=t.loginAPIEndpoint,r=t.logoutAPIEndpoint,i=t.onLoginRequestError,o=t.onLogoutRequestError,e.id?((0,f.Z)("[withUser] Calling the login endpoint."),[4,e.getIdToken()]):[3,11];case 1:if(a=d.sent(),!n)throw new Error("Invalid config.");d.label=2;case 2:return d.trys.push([2,6,,10]),[4,fetch(n,{method:"POST",headers:{Authorization:a||void 0},credentials:"include"})];case 3:return(s=d.sent()).ok?[3,5]:[4,s.json()];case 4:throw l=d.sent(),(0,f.Z)("[withUser] The call to the login endpoint failed with status ".concat(s.status," and response: ").concat(JSON.stringify(l))),new Error("Received ".concat(s.status," response from login API endpoint: ").concat(JSON.stringify(l)));case 5:return[3,10];case 6:return u=d.sent(),i&&u instanceof Error?[4,i(u)]:[3,8];case 7:return d.sent(),[3,9];case 8:throw u;case 9:return[3,10];case 10:return[3,20];case 11:if((0,f.Z)("[withUser] Calling the logout endpoint."),!r)throw new Error("Invalid config.");d.label=12;case 12:return d.trys.push([12,16,,20]),[4,fetch(r,{method:"POST",credentials:"include"})];case 13:return(s=d.sent()).ok?[3,15]:[4,s.json()];case 14:throw l=d.sent(),(0,f.Z)("[withUser] The call to the logout endpoint failed with status ".concat(s.status," and response: ").concat(JSON.stringify(l))),new Error("Received ".concat(s.status," response from logout API endpoint: ").concat(JSON.stringify(l)));case 15:return[3,20];case 16:return h=d.sent(),o&&h instanceof Error?[4,o(h)]:[3,18];case 17:return d.sent(),[3,19];case 18:throw h;case 19:return[3,20];case 20:return[2,s]}}))}))},g=function(e){return d(void 0,void 0,void 0,(function(){var t,n;return p(this,(function(r){return t=(0,c.i)().tokenChangedHandler,n=(0,o.Z)({firebaseUserClientSDK:e,clientInitialized:!0}),t?((0,f.Z)('[withUser] Calling the custom "tokenChangedHandler" provided in the config.'),[2,t(n)]):[2,v(n)]}))}))};const y=function(){var e=(0,s.useState)({user:null,claims:{},initialized:!1}),t=e[0],n=e[1],r=(0,s.useState)(!1),i=r[0],o=r[1];return(0,s.useEffect)((function(){var e=!1,t=(0,c.i)().firebaseClientAppName,r=(0,a.getApp)(t),i=(0,u.onIdTokenChanged)((0,u.getAuth)(r),(function(t){return d(void 0,void 0,void 0,(function(){var r,i;return p(this,(function(s){switch(s.label){case 0:return(0,f.Z)("[withUser] The Firebase ID token changed. New Firebase user:",t),o(!1),r={},t?[4,(0,u.getIdTokenResult)(t)]:[3,2];case 1:i=s.sent(),r=(0,l.Y)(i.claims),s.label=2;case 2:return n({user:t,claims:r,initialized:!0}),[4,g(t||void 0)];case 3:return s.sent(),e?(0,f.Z)("[withUser] Component unmounted before completing the auth API request."):(o(!0),(0,f.Z)("[withUser] Completed the auth API request.")),[2]}}))}))}));return function(){i(),e=!0}}),[]),h(h({},t),{authRequestCompleted:i})};var b=n(718),m=n(245),w=n(739),k=function(){return k=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},k.apply(this,arguments)};const T=function(e){var t=void 0===e?{}:e,r=t.whenAuthed,s=void 0===r?b.g.RENDER:r,a=t.whenUnauthedBeforeInit,u=void 0===a?b.g.RENDER:a,c=t.whenUnauthedAfterInit,l=void 0===c?b.g.RENDER:c,h=t.whenAuthedBeforeRedirect,d=void 0===h?b.g.RETURN_NULL:h,p=t.appPageURL,v=t.authPageURL,g=t.LoaderComponent,T=void 0===g?null:g;return function(e){(0,f.Z)('[withUser] Calling "withUser".');try{var t=n(689),r=n(689),a=r.useEffect,c=r.useCallback,h=r.useMemo,g=n(853).useRouter,E=n(355).S}catch(e){throw"MODULE_NOT_FOUND"===e.code?new Error('The dependencies "react" and "next" are required when calling `withUser`.'):e}var x=function(n){var r=n.userSerialized,i=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(n,["userSerialized"]),x=h((function(){return(0,o.Z)({serializedUser:r})}),[r]),S=y(),O=S.user,A=S.claims,R=S.initialized,C=S.authRequestCompleted,I=h((function(){return(0,o.Z)({firebaseUserClientSDK:O||void 0,clientInitialized:R,claims:A})}),[O,R,A]),U=R?I:x,P=!!U.id,Z=U.clientInitialized,_=P&&s===b.g.REDIRECT_TO_APP,D=_&&(0,m.Z)()&&C,q=!P&&(!Z&&u===b.g.REDIRECT_TO_LOGIN||Z&&l===b.g.REDIRECT_TO_LOGIN),L=q&&(0,m.Z)()&&(u===b.g.REDIRECT_TO_LOGIN||C),N=g(),j=c((function(e){var t=e.basePath,n=e.destination;!1===t?window.location.replace(n):N.replace(n)}),[N]),H=c((function(){(0,f.Z)("[withUser] Redirecting to app.");var e=(0,w.j)({user:U,redirectURL:p});j(e)}),[U,j]),F=c((function(){(0,f.Z)("[withUser] Redirecting to login.");var e=(0,w.U)({user:U,redirectURL:v});j(e)}),[U,j]);a((function(){(0,m.Z)()&&(D?H():L&&F())}),[D,L,H,F]);var z,M=T?t.createElement(T,null):null,K=t.createElement(E.Provider,{value:U},t.createElement(e,k({},i)));return z=_?d===b.g.RENDER?K:d===b.g.SHOW_LOADER?M:null:q?u===b.g.RETURN_NULL?null:u===b.g.SHOW_LOADER?M:K:P||C?K:u===b.g.SHOW_LOADER?M:u===b.g.RETURN_NULL?null:K,(0,f.Z)("[withUser] Set user to:",U),z};return x.displayName="WithUserHOC",i()(x,e),x}}},919:(e,t,n)=>{n.d(t,{Z:()=>u});var r=n(951),i=n(718),o=n(739),s=n(163),a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};const u=function(e,t){var n=void 0===e?{}:e,u=n.whenAuthed,c=void 0===u?i.g.RENDER:u,l=n.whenUnauthed,f=void 0===l?i.g.RENDER:l,h=n.appPageURL,d=void 0===h?void 0:h,p=n.authPageURL,v=void 0===p?void 0:p,g=(void 0===t?{}:t).useToken,y=void 0===g||g;return function(e){return function(t){return n=void 0,u=void 0,h=function(){var n,u,l,h;return function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(p){switch(p.label){case 0:return(0,s.Z)('[withUserSSR] Calling "withUserSSR" / "withUserTokenSSR".'),n=t.req,[4,(0,r.Z)({req:n,includeToken:y})];case 1:return u=p.sent(),l=u.serialize(),u.id||f!==i.g.REDIRECT_TO_LOGIN?u.id&&c===i.g.REDIRECT_TO_APP?((0,s.Z)("[withUserSSR] Redirecting to app."),[2,{redirect:(0,o.j)({ctx:t,user:u,redirectURL:d})}]):e?(t.user=u,[4,e(t)]):[3,3]:((0,s.Z)("[withUserSSR] Redirecting to login."),[2,{redirect:(0,o.U)({ctx:t,user:u,redirectURL:v})}]);case 2:if(h=p.sent()||{}){if("props"in h)return[2,a(a({},h),{props:a(a({},h.props||{}),{userSerialized:l})})];if("notFound"in h||"redirect"in h)return[2,a({},h)]}p.label=3;case 3:return[2,{props:{userSerialized:l}}]}}))},new((l=void 0)||(l=Promise))((function(e,t){function r(e){try{o(h.next(e))}catch(e){t(e)}}function i(e){try{o(h.throw(e))}catch(e){t(e)}}function o(t){var n;t.done?e(t.value):(n=t.value,n instanceof l?n:new l((function(e){e(n)}))).then(r,i)}o((h=h.apply(n,u||[])).next())}));var n,u,l,h}}}},352:e=>{e.exports=require("depd")},324:e=>{e.exports=require("firebase/app")},610:e=>{e.exports=require("firebase/auth")},815:e=>{e.exports=require("keygrip")},853:e=>{e.exports=require("next/router")},689:e=>{e.exports=require("react")},469:e=>{e.exports=require("react-is")},685:e=>{e.exports=require("http")}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{n.r(r),n.d(r,{AuthAction:()=>i.g,getUserFromCookies:()=>o.Z,init:()=>h,setAuthCookies:()=>l,unsetAuthCookies:()=>f,useUser:()=>d,verifyIdToken:()=>s.y,withUser:()=>p,withUserSSR:()=>v,withUserTokenSSR:()=>g});var e=n(795),t=n(163);var i=n(718),o=n(951),s=n(157),a=n(681),u=n(728),c=n(63);const l=function(n,r,i){var o,l,f,h,d=(void 0===i?{}:i).token;return o=void 0,l=void 0,h=function(){var i,o,l,f,h,p;return function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(v){switch(v.label){case 0:if((0,t.Z)("[setAuthCookies] Attempting to set auth cookies."),!(i=d||n.headers.authorization))throw new Error('The request must have an Authorization header value, or you should explicitly provide an ID token to "setAuthCookies".');o=null,l=null,f=(0,c.Z)(),v.label=1;case 1:return v.trys.push([1,3,,4]),[4,(0,s._)(i)];case 2:return p=v.sent(),o=p.idToken,l=p.refreshToken,f=p.user,[3,4];case 3:return v.sent(),(0,t.Z)("[setAuthCookies] Failed to verify the ID token. Cannot authenticate the user or get a refresh token."),[3,4];case 4:return h=function(e){return{domain:e.domain,httpOnly:e.httpOnly,keys:e.keys,maxAge:e.maxAge,overwrite:e.overwrite,path:e.path,sameSite:e.sameSite,secure:e.secure,signed:e.signed}}((0,e.i)().cookies),(0,a.d8)((0,u.Mb)(),JSON.stringify({idToken:o,refreshToken:l}),{req:n,res:r},h),(0,a.d8)((0,u.P0)(),f.serialize({includeToken:!1}),{req:n,res:r},h),f.id?(0,t.Z)("[setAuthCookies] Set auth cookies for an authenticated user."):(0,t.Z)("[setAuthCookies] Set auth cookies. The user is not authenticated."),[2,{idToken:o,refreshToken:l,user:f}]}}))},new((f=void 0)||(f=Promise))((function(e,t){function n(e){try{i(h.next(e))}catch(e){t(e)}}function r(e){try{i(h.throw(e))}catch(e){t(e)}}function i(t){var i;t.done?e(t.value):(i=t.value,i instanceof f?i:new f((function(e){e(i)}))).then(n,r)}i((h=h.apply(o,l||[])).next())}))};const f=function(n,r){return i=void 0,o=void 0,c=function(){var i;return function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(o){return i=function(e){return{domain:e.domain,httpOnly:e.httpOnly,keys:e.keys,maxAge:e.maxAge,overwrite:e.overwrite,path:e.path,sameSite:e.sameSite,secure:e.secure,signed:e.signed}}((0,e.i)().cookies),(0,a.kT)((0,u.Mb)(),{req:n,res:r},i),(0,a.kT)((0,u.P0)(),{req:n,res:r},i),(0,t.Z)("[unsetAuthCookies] Unset auth cookies."),[2]}))},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{a(c.next(e))}catch(e){t(e)}}function r(e){try{a(c.throw(e))}catch(e){t(e)}}function a(t){var i;t.done?e(t.value):(i=t.value,i instanceof s?i:new s((function(e){e(i)}))).then(n,r)}a((c=c.apply(i,o||[])).next())}));var i,o,s,c};var h=function(n){!function(n){(0,t.y)(!0===(null==n?void 0:n.debug)),(0,e.v)(n)}(n)},d=function(){try{n(689)}catch(e){throw new Error('The dependency "react" is required when calling `useUser`.')}return(0,n(355).Z)()},p=function(e){return(0,n(85).Z)(e)},v=function(e){return(0,n(919).Z)(e,{useToken:!1})},g=function(e){return(0,n(919).Z)(e,{useToken:!0})}})(),module.exports=r})();