Skip to content

Possibility to Generate For AuthProtect endpoints? #11

Open
@erewok

Description

@erewok

Hello,

I have been using this library in a personal project and it's pretty damn cool. Thank you for writing it and for releasing it.

I did have a question, though, about AuthProtect endpoints. I have been using the servant-auth-cookie library to generate sessions and enforce authentication for certain endpoints, but I have not been able to use servant-elm to generate Api calls for these endpoints.

Maybe an example would be illustrative. With an endpoint like this:

type AdminApi = 
  "admin" :> AuthProtect "cookie-auth" :> Get '[HTML] Html
  :<|> "admin" :> "post" :> ReqBody '[JSON] Post.BlogPost :> AuthProtect "cookie-auth" :> Post '[JSON] Post.BlogPost

If I try to generate Elm for this using servant-elm, I get a compiler error like this:

client/GenerateElm.hs:21:9: error:
     No instance for (Servant.Foreign.Internal.HasForeign
                         servant-elm-0.1.0.2:Servant.Elm.Foreign.LangElm
                         elm-export-0.3.0.0:Elm.Type.ElmTypeExpr
                         (Servant.API.Experimental.Auth.AuthProtect "cookie-auth"
                          Servant.API.Sub.:> Servant.API.Verbs.Post
                                               '[Servant.API.ContentTypes.JSON]
                                               Post.BlogPost))
        arising from a use of generateElmForAPI
     In the second argument of (:), namely
        generateElmForAPI adminProxyApi
      In the second argument of (:), namely
        defElmImports : generateElmForAPI adminProxyApi
      In the second argument of (:), namely
        "import Exts.Date exposing (..)"
         : defElmImports : generateElmForAPI adminProxyApi
make: *** [Api.elm] Error 1

Am I doing something wrong or must there be an instance defined to be able to handle AuthProtected endpoints?

Thanks for any suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions