Solution for advanced/part1
This commit is contained in:
@@ -11,17 +11,17 @@ import Username exposing (Username)
|
||||
-- TYPES
|
||||
|
||||
|
||||
type alias Cred =
|
||||
-- 👉 TODO make Cred an opaque type, then fix the resulting compiler errors.
|
||||
-- Afterwards, it should no longer be possible for any other module to access
|
||||
-- this `token` vale directly!
|
||||
--
|
||||
-- 💡 HINT: Other modules still depend on being able to access the
|
||||
-- `username` value. Expand this module's API to expose a new way for them
|
||||
-- to access the `username` without also giving them access to `token`.
|
||||
{ username : Username
|
||||
, token : String
|
||||
}
|
||||
type Cred
|
||||
= Cred Username String
|
||||
|
||||
|
||||
|
||||
-- INFO
|
||||
|
||||
|
||||
username : Cred -> Username
|
||||
username (Cred uname _) =
|
||||
uname
|
||||
|
||||
|
||||
|
||||
@@ -40,14 +40,14 @@ decoder =
|
||||
|
||||
|
||||
encodeToken : Cred -> Value
|
||||
encodeToken cred =
|
||||
Encode.string cred.token
|
||||
encodeToken (Cred _ token) =
|
||||
Encode.string token
|
||||
|
||||
|
||||
addHeader : Cred -> RequestBuilder a -> RequestBuilder a
|
||||
addHeader cred builder =
|
||||
addHeader (Cred _ token) builder =
|
||||
builder
|
||||
|> withHeader "authorization" ("Token " ++ cred.token)
|
||||
|> withHeader "authorization" ("Token " ++ token)
|
||||
|
||||
|
||||
addHeaderIfAvailable : Maybe Cred -> RequestBuilder a -> RequestBuilder a
|
||||
|
||||
Reference in New Issue
Block a user