AngularJS ui-router login authentication

前端 未结 10 2434
[愿得一人]
[愿得一人] 2020-11-22 11:13

I am new to AngularJS, and I am a little confused of how I can use angular-\"ui-router\" in the following scenario:

I am building a web application which consists of

10条回答
  •  伪装坚强ぢ
    2020-11-22 11:30

    I think you need a service that handle the authentication process (and its storage).

    In this service you'll need some basic methods :

    • isAuthenticated()
    • login()
    • logout()
    • etc ...

    This service should be injected in your controllers of each module :

    • In your dashboard section, use this service to check if user is authenticated (service.isAuthenticated() method) . if not, redirect to /login
    • In your login section, just use the form data to authenticate the user through your service.login() method

    A good and robust example for this behavior is the project angular-app and specifically its security module which is based over the awesome HTTP Auth Interceptor Module

    Hope this helps

提交回复
热议问题