adds session authentication
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user