adds session authentication

This commit is contained in:
2019-11-14 12:33:07 +01:00
parent b20a582a42
commit 0d5cc365fc
3 changed files with 99 additions and 35 deletions

View File

@@ -1,13 +1,41 @@
module Session exposing (Session(..), playerSession)
module Session exposing (Session(..), init, playerSession)
import Browser.Navigation as Nav
import Api
import Http
import Json.Decode as D
type Session
= Player Nav.Key Int
-- | Admin Nav.Key
playerSession navKey playerId =
Player navKey playerId
init : (Maybe Session -> msg) -> Nav.Key -> Cmd msg
init toMsg navKey =
let
toSession : Result Http.Error String -> msg
toSession response =
case Debug.log "got session:" response of
Ok value ->
case String.toInt value of
Just id ->
toMsg <| Just (Player navKey id)
Nothing ->
toMsg
Nothing
Err _ ->
toMsg Nothing
in
Http.get
{ url = "http://localhost:8088/session"
, expect = Http.expectJson toSession D.string
}