yada

conan 2019-05-28T13:42:57.004Z

how would i use ring middleware with a yada resource?

conan 2019-05-28T13:45:42.004500Z

i can't work out how to get a ring handler

conan 2019-05-28T13:47:18.005200Z

the manual (https://juxt.pro/yada/manual/index.html#_resources_as_ring_handlers) says I can use yada/handler to get a ring handler, but it returns me a yada.handler.Handler rather than a function which takes the request and returns the response

malcolmsparks 2019-05-28T14:16:21.006200Z

Actually you can treat that record as a fn since it satisfies IFn.

malcolmsparks 2019-05-28T14:17:05.007300Z

But, yada handlers are not Ring handlers as they return async values since yada is async

dominicm 2019-05-28T14:24:11.007700Z

They are aleph handlers I suppose?

dominicm 2019-05-28T14:24:44.008400Z

I've never had ring middleware that I needed with yada, @conan what's the use-case?

conan 2019-05-28T14:34:58.008700Z

i want to redirect users off-site to perform auth

dominicm 2019-05-28T14:35:58.010600Z

In yada you would solve that differently. You would attach a 401 handler to your resources using either a custom resource function or a postwalk over your resources.

conan 2019-05-28T14:36:10.011Z

ideally i'd wrap collections of routes in some middleware, but my understanding is that yada prefers this to be pushed down into the handlers, so i'm trying to wrap my handlers in something that will bypass the handler function and return a 307 in certain circumstances

conan 2019-05-28T14:36:41.011500Z

i don't want to return 401 in these instances, the aim is to redirect the user

malcolmsparks 2019-05-28T14:37:50.012600Z

Yes, push down to each handler. The idea is that web resources are testable independent of routing

dominicm 2019-05-28T14:38:13.012700Z

Correct. A 401 handler is run when a 401 has been produced. You get the option to produce a new result.

conan 2019-05-28T14:38:42.013Z

right but i don't want to produce 401 here

conan 2019-05-28T14:40:25.014500Z

that'll come later. after completing authentication, we'll issue the user with a cookie that will provide them access to our API resources; in the case that this cookie is not valid for some reason, we'll return a 401. there's no point doing that when they don't have a cookie; it would be possible to serve the client-side SPA and have it handle the 401, but that would make everything painfully slow

conan 2019-05-28T14:41:18.015200Z

the most common path will be no-cookie > auth > cookie > API, and that's what i'm aiming to optimise for

dominicm 2019-05-28T14:41:27.015600Z

The lack of cookie will trigger a 401 from your authenticator.

conan 2019-05-28T14:42:49.016500Z

yeah i can set up the yada-security/verify function to do that, but I don't want to send a 401 when there's no cookie - in fact, I don't even want to do any routing when there's no cookie. if you don't have a cookie, you're on the wrong site

conan 2019-05-28T14:43:33.017200Z

is there a way to intercept the request? perhaps that's a bidi question rather than a yada one?

malcolmsparks 2019-05-28T14:44:17.018Z

Yes, you can add an interceptor. You should intercept resources not routing.

conan 2019-05-28T14:46:08.019300Z

OK, so I think i'm on the right track, i'm writing a function to wrap a resource, but what i don't know is how i can turn a yada resource into something i can use with ring middelware - if i wrap any resource in middleware it seems to give no response

conan 2019-05-28T14:46:27.019600Z

(that includes wrapping the resource in yada/handler first)

malcolmsparks 2019-05-28T14:47:59.021900Z

Have you tried deref on the response? You'd need to wrap the handler in a wrapper that would deref the response. But that would break the async model so there are performance tradeoffs

conan 2019-05-28T14:50:56.022600Z

is there a way to bypass that?

conan 2019-05-28T14:51:10.022900Z

i don't need to create futures and things, they will never be used in this scenario

conan 2019-05-28T14:52:20.023800Z

there won't be a performance tradeoff here as we don't need to do anything except send a redirect, i don't think that can be made any faster

dominicm 2019-05-28T14:55:28.025200Z

Fwiw, I'm not recommending you produce a 401 to the end user, I'm saying that yada let's you override the behaviour of the 401 and convert it to a 301

conan 2019-05-28T14:57:14.025700Z

oh you mean change the 401 response after it's been produced?

conan 2019-05-28T14:57:44.026100Z

that seems a bit hacky, is there a recommended approach to changing the response?

dominicm 2019-05-28T14:58:49.026700Z

The yada author does it in his software 😛 , not hacky afaik

conan 2019-05-28T14:59:22.026900Z

ok i'll give it a shot, thanks

dominicm 2019-05-28T15:00:40.027600Z

That rewrite behaviour is in the manual, one sec

malcolmsparks 2019-05-28T15:00:55.027900Z

Status responses