javascript - Angular refresh kills user session -


There is a problem with my angular app - after a user's prompt, if he kills the fresh button, signin The information is lost and the app redirects to the login page. I got an answer for something similar but I do not think it can work for me because I am not using cookies. Can anybody recommend the solution? Here is my authorization service -

  var app = angular Module ('myapp.services'); App.factory ('signin', ['$ resource', '$ q', function ($ resource, $ Q) {var signInUrl = 'https://example.com' var API = $ resource (sign in URL, { }, {User}: {signin: {with credentials: true, url: signInUrl + '/ session', method: 'POST'}, signature: {url: authApiUrl + '/ session', method: 'DELETE'} Url: signInUrl + '/ user / @m', method: 'GET'}} var _currentUser = undefined; return {isAuthenticated: function () {return! _ Current user;}, getUser: function () {var d = $ Q Defer (); // If _currentUser is undefined we should get current user (_currentUser === undefined) {API.c UrrentUser (function (userData) {_currentUser = userData; d.resolve (userData);}, function (response) {If (response.statusCode === 401} {_currentUser = null; d.resolve (_currentUser);} else { D.reject ();}});} Other {d.rolog (_currentUser);} Return D.promise;}, signIn: function (username, password) {var d = $ q.defer (); API .signIn ({Email: Username, Password: Password}, ​​Function (Data, Header) {_cu RrentUser = Data; D.resolve (_currentUser); }, D.reject); Return d.promise; }, Signature: function () {var d = $ q.defer (); API.signOut (function () {_currentUser = null; d.resolve ();}, d.reject); Return d.promise; }}; }];  

If you need to keep track of _currentUser data before refreshing you You can use sessionStorage in the browser, it extends all the way back to IE8 and we really should not support any browsers before this.

Generally these things are done with cookies, although when a customer first creates a connection to the server (in some cases before the API call before the call) a cookie is sent to the client, then the server Can maintain the session associated with that specific client. This is because the cookie is automatically sent back to the server with each request, and the server can see its local session and can say, "Oh, I'm talking to the this user Now I can use that extra piece to know about the context whether I can satisfy my API call. "

You do not show any of your other API calls here Are Ekin send me the feeling that you _currentUser each API call to identify the user instead? If so, it definitely works, and it avoids the need to synchronize cookies on many servers if you are clustering the server, but you will have to use some locally-like sessionstraw or local storage which Will not be dumped like your current - memory copy of data when you refresh the page.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -