热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ionic和Firebase用户身份验证,页面限制-IonicandFirebaseUserAuthentication,pagerestriction

IhavebuiltasimpleappthatletsyouregisteranaccountusingFirebaseAuthandlogin.我已经构建了一个

I have built a simple app that lets you register an account using Firebase Auth and login.

我已经构建了一个简单的应用程序,可让您使用Firebase Auth注册帐户并登录。

I used Ionics starter "tab" application for this. I followed the tutorial here: https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-routers

我为此使用了Ionics启动器“tab”应用程序。我按照教程:https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-routers

for preventing routes based on the Auth state of the user. using the code below, i've prevented you from accessing the dashboard tab without being logged in just for testing purposes however, you can still access it. I followed the tutorial step by step and this is what I have.

用于根据用户的Auth状态阻止路由。使用下面的代码,我已经阻止您访问仪表板选项卡而不是为了测试目的登录,但是,您仍然可以访问它。我一步一步地按照教程,这就是我所拥有的。

app.js

// Before anything else I define firebase, create a reference to the url, 
// create a service for the url and create the Auth function.

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase'])

   .constant('FirebaseUrl', 'https://.firebaseio.com/')

   .service('rootRef', ['FirebaseUrl', Firebase])

   .factory("Auth", ["$firebaseAuth", function($firebaseAuth) {
      var ref = new Firebase("https://.firebaseio.com/");
      return $firebaseAuth(ref);
   }])

   ...

app.js .run()

// Then in my `.run()` function I listen for our state change that fails  
// because it needs to authorized first.

.run(function($rootScope, $state, $ionicPlatform) {

  // ionic init. code here

  $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
     // We can catch the error thrown when the $requireAuth promise is rejected
     // and redirect the user back to the login page
     if(error === "AUTH_REQUIRED") {
         $state.go("login");
     }
  });
})

app.js .config()

// Finally in my `.config()` I have my $stateProvider set up and my dashboard
// tab is resolving as to have auth required to view.

.config(function($stateProvider, $urlRouterProvider) {

    $stateProvider

    // setup an abstract state for the tabs directive
    .state('tab', {
       url: '/tab',
       abstract: true,
       templateUrl: 'templates/tabs.html'
    })

    .state('login', {
       url: '/login',
       templateUrl: 'templates/login.html',
       controller: 'LoginCtrl as ctrl'
    })

    .state('tab.dash', {
       url: '/dash',
       views: {
         'tab-dash': {
            templateUrl: 'templates/tab-dash.html',
            controller: 'DashCtrl'
         }
       },
       resolve : {
         // controller will not be loaded until $waitForAuth resolves
         // Auth refers to our $firebaseAuth wrapper in the example above
         currentAuth: ["Auth", function(Auth) {
           // $waitForAuth returns a promise so the resolve waits for it to complete
           return Auth.$waitForAuth();
         }]
       }
     })

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/login');

});

regardless of all this, when I click a temporary link on the login page (where the app starts) it still takes me to the dashboard page, even when not logged in!

无论如何,当我点击登录页面上的临时链接(应用程序启动的地方)时,即使没有登录,它仍然会将我带到仪表板页面!

What am I missing here?

我在这里想念的是什么?

1 个解决方案

#1


0  

In the example you posted it says In the example you posted on the firebase site it says return Auth.$requireAuth(); and you have return Auth.$waitForAuth();

在您发布的示例中,在您在firebase网站上发布的示例中,它返回Auth。$ requireAuth();你已经返回Auth。$ waitForAuth();


推荐阅读
  • HSRP热备份路由器协议的应用及配置
    本文介绍了HSRP热备份路由器协议的应用及配置方法,包括设计目标、工作原理、配置命令等。通过HSRP协议,可以实现在主动路由器故障时自动切换到备份路由器,保证网络连通性。此外,还介绍了R1和R2路由器的配置方法以及Sw1和Sw2交换机的配置方法,最后还介绍了测试连通性和路由追踪的方法。 ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
  • Vue基础一、什么是Vue1.1概念Vue(读音vjuː,类似于view)是一套用于构建用户界面的渐进式JavaScript框架,与其它大型框架不 ... [详细]
  • NSD cisco高级路由与交换技术2014.8.12
    实验01:DHCP服务的应用实验目标:通过建立DHCP服务,给计算机自动分配地址实验环境:实验步骤:一、配置计算机pc8pc ... [详细]
  • 使用nodejs爬取b站番剧数据,计算最佳追番推荐
    本文介绍了如何使用nodejs爬取b站番剧数据,并通过计算得出最佳追番推荐。通过调用相关接口获取番剧数据和评分数据,以及使用相应的算法进行计算。该方法可以帮助用户找到适合自己的番剧进行观看。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • javascript  – 概述在Firefox上无法正常工作
    我试图提出一些自定义大纲,以达到一些Web可访问性建议.但我不能用Firefox制作.这就是它在Chrome上的外观:而那个图标实际上是一个锚点.在Firefox上,它只概述了整个 ... [详细]
  • Firefox火狐浏览器关闭到http://detectportal.firefox.com的流量问题解决办法
    本文介绍了使用Firefox火狐浏览器时出现关闭到http://detectportal.firefox.com的流量问题,并提供了解决办法。问题的本质是因为火狐默认开启了Captive portal技术,当连接需要认证的WiFi时,火狐会跳出认证界面。通过修改about:config中的network.captive-portal-service.en的值为false,可以解决该问题。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • 本文介绍了在交换型网络环境下使用嗅探器ARPSniffer的方法,包括检测嗅探环境、设置嗅探的网卡和启动自动路由功能等步骤。同时指出ARPSniffer也可以在非交换型网络环境下使用来嗅探各种网络信息。 ... [详细]
author-avatar
青峰的兔子饭团
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有