UNPKG

angular-meteor-auth

Version:

Angular-Meteor authentication module

3 lines 2.65 kB
/*! angular-meteor-auth v1.1.1 */ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.angularMeteorAuth=r():e.angularMeteorAuth=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var t="angular-meteor.auth";r.default=t,angular.module(t,["angular-meteor.mixer","angular-meteor.scope","angular-meteor.core","angular-meteor.view-model","angular-meteor.reactive"]).factory("$$Auth",["$Mixer","$log","$q",function(e,r,t){function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;this.autorun(function(){e.currentUser=Meteor.user(),e.currentUserId=Meteor.userId(),e.isLoggingIn=Meteor.loggingIn()})}var o=(Package["accounts-base"]||{}).Accounts;if(!o)throw Error("`angular-meteor.auth` module requires `accounts-base` package, please run `meteor add accounts-base` before use");var u={required:"AUTH_REQUIRED",forbidden:"FORBIDDEN"};return n.$awaitUser=function(r){var n=this;if(r=r?this.$bindToContext(e.caller,r):function(){return!0},!_.isFunction(r))throw Error("argument 1 must be a function");var o=this.$$defer();if(this.currentUser)return o.resolve(this.currentUser),o.promise.stop=angular.noop,o.promise;var i=this.autorun(function(e){if(!n.getReactively("isLoggingIn"))return e.stop(),n.currentUser?void t.when(r(n.currentUser)).then(function(e){return e!==!0?t.reject(e):void n.$$afterFlush(o.resolve,n.currentUser)}).catch(function(e){var r=void 0;r=_.isString(e)||e instanceof Error?e:u.forbidden,n.$$afterFlush(o.reject,r)}):n.$$afterFlush(o.reject,u.required)});return o.promise.stop=i.stop.bind(i),o.promise},n.$$afterFlush=function(e){var r;_.isString(e)&&(e=this[e]);for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return Tracker.afterFlush((r=e).bind.apply(r,[this].concat(n)))},n.$waitForUser=function(){return this.$awaitUser().catch(function(e){r.debug("user login has failed ("+e+")")})},n.$requireUser=function(){return this.$awaitUser()},n.$requireValidUser=function(){return this.$awaitUser.apply(this,arguments)},n}]).service("$auth",["$rootScope","$$Auth",function(e,r){var t=this;_.keys(r).forEach(function(r){var n=r.substr(1);t[n]=function(){return e[r].apply(e,arguments)}})}]).run(["$Mixer","$$Auth",function(e,r){e.mixin(r)}]),e.exports=r.default}])}); //# sourceMappingURL=angular-meteor-auth.min.js.map