I made this module yesterday to notify me when a JWT bearer token expires. Thought I would share in case anyone found useful, maybe make a package later.
https://gist.github.com/kspeakman/bd13d5b922a6abfcbb480a907161030c Basic usage (ignoring JWT parse errors) is: jwtString |> Jwt.onExpired Logout |> Result.withDefault Cmd.none This should be run one time. I run either on program init (jwt loaded from local storage and passed in through flags) or when token is received on login. When the expiration time comes, it will send back whatever message you specify (e.g. Logout). Our use cases currently don't have users repeatedly logging in/out or swapping logins, so I'm not dealing with canceling the expiration notification. If I needed to deal with this for now, I would probably just refresh the page on logout to kill the sleeping process (which is just Javascript's `setTimeout`). Or ignore notifications from old tokens (match token signature?). I used a couple of internal functions from elm-jwt <https://github.com/simonh1000/elm-jwt> for converting JWT back to proper Base64. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
