react-firebase-hooks
Version:
React Hooks for Firebase
3 lines (2 loc) • 3.75 kB
JavaScript
!function(e,r){"use strict";var t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var u in r=arguments[t])Object.prototype.hasOwnProperty.call(r,u)&&(e[u]=r[u]);return e}).apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))(function(u,a){function o(e){try{s(n.next(e))}catch(e){a(e)}}function i(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){e.done?u(e.value):new t(function(r){r(e.value)}).then(o,i)}s((n=n.apply(e,r||[])).next())})}function u(e,r){var t,n,u,a,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;o;)try{if(t=1,n&&(u=2&a[0]?n.return:a[0]?n.throw||((u=n.return)&&u.call(n),0):n.next)&&!(u=u.call(n,a[1])).done)return u;switch(n=0,u&&(a=[2&a[0],u.value]),a[0]){case 0:case 1:u=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(u=(u=o.trys).length>0&&u[u.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!u||a[1]>u[0]&&a[1]<u[3])){o.label=a[1];break}if(6===a[0]&&o.label<u[1]){o.label=u[1],u=a;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(a);break}u[2]&&o.ops.pop(),o.trys.pop();continue}a=r.call(e,o)}catch(e){a=[6,e],n=0}finally{t=u=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}var a=function(e){return{loading:void 0===e||null===e,value:e}},o=function(e){var n=e?e():void 0,u=r.useReducer(function(e,r){switch(r.type){case"error":return t({},e,{error:r.error,loading:!1,value:void 0});case"reset":return a(r.defaultValue);case"value":return t({},e,{error:void 0,loading:!1,value:r.value});default:return e}},a(n)),o=u[0],i=u[1],s=function(){var r=e?e():void 0;i({type:"reset",defaultValue:r})},c=function(e){i({type:"error",error:e})},l=function(e){i({type:"value",value:e})};return r.useMemo(function(){return{error:o.error,loading:o.loading,reset:s,setError:c,setValue:l,value:o.value}},[o.error,o.loading,s,c,l,o.value])};e.useAuthState=function(e){var t=o(function(){return e.currentUser}),n=t.error,u=t.loading,a=t.setError,i=t.setValue,s=t.value;r.useEffect(function(){var r=e.onAuthStateChanged(i,a);return function(){r()}},[e]);var c=[s,u,n];return r.useMemo(function(){return c},c)},e.useSignInWithEmailAndPassword=function(e){var t=r.useState(),a=t[0],o=t[1],i=r.useState(),s=i[0],c=i[1],l=r.useState(!1),f=l[0],v=l[1],d=[function(r,t){return n(void 0,void 0,void 0,function(){var n,a;return u(this,function(u){switch(u.label){case 0:v(!0),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,e.signInWithEmailAndPassword(r,t)];case 2:return n=u.sent(),c(n),v(!1),[3,4];case 3:return a=u.sent(),o(a),v(!1),[3,4];case 4:return[2]}})})},s,f,a];return r.useMemo(function(){return d},d)},e.useCreateUserWithEmailAndPassword=function(e,t){var a=r.useState(),o=a[0],i=a[1],s=r.useState(),c=s[0],l=s[1],f=r.useState(!1),v=f[0],d=f[1],h=[function(r,a){return n(void 0,void 0,void 0,function(){var n,o;return u(this,function(u){switch(u.label){case 0:d(!0),u.label=1;case 1:return u.trys.push([1,5,,6]),[4,e.createUserWithEmailAndPassword(r,a)];case 2:return n=u.sent(),t&&t.sendEmailVerification&&n.user?[4,n.user.sendEmailVerification(t.emailVerificationOptions)]:[3,4];case 3:u.sent(),u.label=4;case 4:return l(n),d(!1),[3,6];case 5:return o=u.sent(),i(o),d(!1),[3,6];case 6:return[2]}})})},c,v,o];return r.useMemo(function(){return h},h)}}(this["react-firebase-hooks"]=this["react-firebase-hooks"]||{},react);
//# sourceMappingURL=react-firebase-hooks-auth.js.map