Discussion:
[elm-discuss] Notify me when JWT expires
Kasey Speakman
2017-04-12 16:57:46 UTC
Permalink
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 elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
art yerkes
2017-04-13 13:56:01 UTC
Permalink
Thanks for sharing this.
--
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 elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...