Add storing login token (but not retrieving it)

This commit is contained in:
Danila Fedorin 2018-12-17 02:34:46 -08:00
parent 720e6db334
commit 6f1e3da27b
3 changed files with 19 additions and 0 deletions

View File

@ -9,9 +9,11 @@ import Scylla.Views exposing (viewFull)
import Scylla.Route exposing (Route(..))
import Scylla.UserData exposing (..)
import Scylla.Notification exposing (..)
import Scylla.Storage exposing (..)
import Url exposing (Url)
import Url.Parser exposing (parse)
import Url.Builder
import Json.Encode
import Html exposing (div, text)
import Http
import Dict
@ -122,6 +124,7 @@ updateLoginResponse model r = case r of
Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId } , Cmd.batch
[ firstSync model.apiUrl lr.accessToken
, Nav.pushUrl model.key <| Url.Builder.absolute [] []
, setStoreValuePort ("scylla.loginInfo", Json.Encode.string (lr.accessToken ++ "\n" ++ model.apiUrl))
] )
Err e -> (model, Cmd.none)

6
src/Scylla/Storage.elm Normal file
View File

@ -0,0 +1,6 @@
port module Scylla.Storage exposing (..)
import Json.Encode
port setStoreValuePort : (String, Json.Encode.Value) -> Cmd msg
port getStoreValuePort : (String) -> Cmd msg
port receiveStoreValuePort : (Json.Encode.Value -> msg) -> Sub msg

10
static/js/storage.js Normal file
View File

@ -0,0 +1,10 @@
function setupStorage(app) {
app.ports.setStoreValuePort.subscribe(function(data) {
key = data[0];
value = data[1];
localStorage.setItem(key, value);
});
app.ports.getStoreValuePort.subscribe(function(data) {
app.ports.receiveStoreValuePort.send(localStorage.getItem(data));
});
}