Base solution for your next web application
Open Closed

Sample app: unify Auth & Unauth angular JS apps #6


User avatar
0
nicnewdigate created

For the sample application, do you have any suggestions how I can use the same Angular SPA for authenticated users and non-authenticated users? Currently, the user is redirected to the login page if they are not logged in. I could have a separate angular app for unauthenticated users, but this will introduce redundancy because unauthenticated users share certain features - say for instance - the public/unauthenticated users should be able to see a list of questions and answers, but only authenticated users will be able to post questions and answers.

Any insight would be appreciated.

Thanks.


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    First of all, if your application will be public, you should also think about SEO if you're using Angular (Fortunately there are some solutions but you should take care of it).

    Actually, it's simple. In the sample app (<a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/tree/master/sample">https://github.com/aspnetboilerplate/mo ... ter/sample</a>), you should remove [AbpAuthorize] of the HomeController. Then MVC will not redirect to login.

    In your angular application, you should check if user logged in and show some menus/links. You should only authorize needed app service methods, not all.

  • User Avatar
    0
    nicnewdigate created

    Thanks @hikalkan! Wow - I wasn't expecting it to be that easy! I'll give it a go.

    Yes I heard that SPAs are notoriously bad with SEO! My buddy says something about a hashbang! I'll have to go investigate it!

    Thanks again :)