Angular-meteor.auth resolve to a blank page


#1

I’m trying to authenticate the user before the view, in this case dashboard, gets rendered.

If the user is logged in, then your good to go, but if not, redirect to login state.

This is my controller:

import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import angularMeteorAuth from 'angular-meteor-auth';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { name as navBar } from '../navBar/navBar';

import './dashboard.html';

class dashboardCtrl {
  constructor($scope) {
    'ngInject';

    if (Meteor.user()) {
      console.log('logged in ', Meteor.user());
    } else {
      console.log('not logged in or error');
    }
  }
}

const name = 'dashboard';

export default angular.module(name, [
  angularMeteor,
  uiRouter,
  navBar,
  angularMeteorAuth
])
  .component(name, {
    templateUrl: `imports/ui/components/${name}/${name}.html`,
    controller: dashboardCtrl,
  })
  .config(function($stateProvider, $urlRouterProvider) {
    'ngInject';

    $stateProvider
    .state('dashboard', {
      url: '/dashboard',
      template: '<dashboard></dashboard>',
      resolve: {
        user: function($auth, $state){
          return $auth.requireUser().then(function(){
            return true;
          }, function(err){
            $state.go('login');
          });
        }
      }
    })
  })

This works fine if the user is not logged in, it will redirect to login normally, but when the user is indeed logged in and you try to refresh in dashboard it returns a blank screen/page with no console logs or errors or anything.

How can I solve this?

Thanks!


#2

I’ve tried using the newer api http://www.angular-meteor.com/api/1.3.6/auth with awaitUser but still no luck :sweat: