Helper functions for Jwt token authentication.
A Jwt Token comprises 3 elements: a header and footer and the content. This package includes a function to send an authentication request, a function to read the content of a token; and a function to send GET requests with the token attached.
decodeToken converts the token content to an Elm record structure.
decoderToken dec tokenIn the event of success, decodeToken returns an Elm record structure using the JSON Decoder.
getWithJwt is a replacement for Http.get that attaches a provided Jwt token
to the headers of the GET request.
getWithJwt model.token "http://localhost:5000/api/restos/test"
|> Task.toResult
|> Task.map AuthData
|> Effects.tasksThe three errors that can emerge are:
authenticateis a custom Http POST method that sends a stringified Json object containing the login credentials. It then extracts the token from the json response from the server and returns it.