all repos

onasty @ d309c75

a one-time notes service

onasty/web/src/JwtUtil.elm (view raw)

Olexandr Smirnov Olexandr Smirnov
ss2316544@gmail.com
web: general refactor (#158)..., 11 months ago
1
module JwtUtil exposing (isExpired)
2
3
import Jwt
4
import Time
5
6
7
{-| Checks if a JWT token is expired or about to expire.
8
-}
9
isExpired : Time.Posix -> String -> Bool
10
isExpired now token =
11
    let
12
        expirationThreshold =
13
            40 * 1000
14
15
        timeDiff =
16
            getTokenExpiration token
17
                |> (\expiration -> expiration - Time.posixToMillis now)
18
    in
19
    timeDiff <= expirationThreshold
20
21
22
getTokenExpiration : String -> Int
23
getTokenExpiration token =
24
    Jwt.getTokenExpirationMillis token |> Result.withDefault 0