Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    session trong AngularJs

    Hỏi Đáp
    1
    6
    1677
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nhật Nguyễn
      Nhật Nguyễn last edited by Nhật Nguyễn

      Các bác cho em hỏi, em code 1 webservice, khi xử lý hàm login xong = passport thì node có lưu session lại, thông qua angular em có gửi thông tin user về client được, Nhưng làm sao trong angular để lưu cái session đó lại được các bác ? ( Tại đang xử lý cái login trên app = ionic)

      1 Reply Last reply Reply Quote 0
      • Bờm
        Bờm last edited by

        Xem localstorage đó bạn, lưu nó xuống rồi lúc user vào lại thì đọc từ storage lên lại

        1 Reply Last reply Reply Quote 0
        • Nhật Nguyễn
          Nhật Nguyễn last edited by

          Nhưng mình làm trên Ionic, mình ko biết sao handle cái session sau khi login, mình có solution là lưu session trên server rồi khi nào mở app thì nó check lại server có session ko, ko biết vậy có ảnh hưởng performance ko?

          1 Reply Last reply Reply Quote 0
          • Bờm
            Bờm last edited by

            Ionic cũng lưu được mà bạn, đọc cái này tham khảo thử
            https://medium.com/@petehouston/awesome-local-storage-for-ionic-with-ngstorage-c11c0284d658#.wfice3g14

            1 Reply Last reply Reply Quote 0
            • N
              Nguyễn Vũ Hữu Trí last edited by

              Khi thao tác với web api bạn nên dùng JWT (Json Web Token) để authorize, node có khá nhiều module có thể xử lí việc này. Trên ionic bạn lưu token sau khi đăng nhập vào localStorage và append vào header của mỗi request theo key và format "Authorization": "Bearer {token}".

              Đồng thời config http interceptor để bắt response code, nếu mã trả về là 401 (Unauthorized) thì xóa token đã lưu và redirect về trang login.

              Lợi ích của JWT có rất nhiều, bạn dùng rồi sẽ thấy và đừng mày mò theo cách khác để để phải bảo trì và sửa lỗi sau này =))

              1 Reply Last reply Reply Quote 0
              • E
                EricHadsell last edited by

                In the development https://banksnear-me.com/arvest/ of children at my school. Aside from this game, I also have some.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                $(document).ready(function () { app.coldLoad(); }); }