Vietnam

    Nodejs.vn

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

    Get JWT token expiry date

    Hỏi Đáp
    0
    3
    819
    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.
    • T
      thanh nam trần last edited by thanh nam trần

      Chào mọi người !
      Em đang làm cái JWT (jsonwebtoken).
      Sau khi tạo ra 1 chuỗi token em muốn lấy được cái time hết hạn của cái token đó nên em đi decode token. Sau khi decode xong nhận về 1 chuỗi timespan, format lại thì nó lại ra 1 cái ngày tháng từ năm nào xa xưa. Em không hiểu tại sao nó lại ra như vậy. Mong mọi người có thể hổ trợ em vụ này. Em cảm ơn !

      Đây là code của em:

      0_1468990347453_upload-ade6d241-1e94-4b8a-bd83-85863c3b249d

      1 Reply Last reply Reply Quote 0
      • Vũ
        Vũ Global Moderator last edited by

        Giá trị exp của jwt trả về con số dưới dạng seconds, mà thằng moment nhận input là miliseconds. Nên bạn cần nhân thêm 1000 nữa để đổi về seconds. Tương tự khi khởi tạo 1 đối tượng new Date. Output của bạn nó sẽ ra như thế này.

        console.log(new Date(1468991677 * 1000))
        // Wed Jul 20 2016 12:14:37 GMT+0700 (SE Asia Standard Time)
        

        Tech-nông
        Email: [email protected]
        Profile: about.me/vunb
        Github: github.com/vunb
        Twitter: twitter.com/nhubaovu

        1 Reply Last reply Reply Quote 4
        • mike
          mike last edited by

          @Vũ great !

          1 Reply Last reply Reply Quote 1
          • First post
            Last post