Hey everyone,

I am having problems figuring out handling session and authentication with 
AngularJS with a Java Spring Backend. I can surely get something up and 
running but I don't want to do something hacky so here I am in need of your 
assistance.

First of all, I will tell you guys what I am using for my environment and 
technology stack.

I am using a JHipster generated project ( 
http://jhipster.github.io/tech_stack.html ). 
JHipster is a YeoMen project generator stack for AngularJS + Java Spring 
Backend + PostgreSQL, MySql or some other databases. It did not include 
Oracle SQL. 
The reason I say this did not include Oracle SQL is because I had to 
configure it myself to include Oracle SQL since that is what I need at my 
work and JHipster does not include Oracle. I also took out Liquidbase 
because it seem too much of a hassle to get working.

A JHipster project includes token based authentication and session set up 
already. My problem is integrating these systems to my own AngularJS 
project. I am not using their full client, so it is not merely just 
changing how the generated views look.

Questions:
How do I check if the session is valid and allow a user to continue using 
contained websites?
For example, say a user logs in at the root page '/'
I want for example the AngularJS app to know that if a user is at '/' and 
the session is valid (the user is logged in), redirect to '/main' or 
redirect to a whole new page instead of injecting main into the index.html

Here are some attempts at trying to get the session and seeing if its valid:

I used a cookie which works.. kind of... however cookies just doesn't seem 
like the right way of doing things.
Everything in the console.log is my attempt at trying to find a value that 
I can use to see if a user is currently logged in with a valid session.

  $rootScope.$on( "$routeChangeStart", function(event, next, current) {
                      $rootScope.isAuthenticated = 
AuthenticationSharedService.isAuthenticated;
                        console.log("in account check");
                        console.log( 
AuthenticationSharedService.isAuthenticated);
                        console.log(Session);
                        console.log(JSON.stringify(Session.login));
                        console.log(!Session.login);
                        console.log(Session.login);
                        console.log( $rootScope.isAuthenticated);
                        //console.log( $cookieStore.get("user"));
                      if ($cookieStore.get("user").login.length > 3) {

                         if ($location.path() === "/") {
                             console.log("Login Detected, go to main");
                            // logged user, redirect to /main
                            $location.path('/main').replace();
                         }
                        }
                    });

Thanks, looking forward to solving this so I can move on to the core of the 
application

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to