grpc-web icon indicating copy to clipboard operation
grpc-web copied to clipboard

Asynchronous intercept method of StreamInterceptor

Open alienvspredator opened this issue 4 years ago • 5 comments

Is it possible to implement promise- or callback- based intercept method of StreamInterceptor like the UnaryInterceptor? For example:

class StreamAuthInterceptor<REQ, RESP> implements StreamInterceptor<REQ, RESP> {
	async intercept(
		r: Request<REQ, RESP>,
		invoker: (r: Request<REQ, RESP>) => ClientReadableStream<RESP>
	): Promise<ClientReadableStream<RESP>> {
		r.getMetadata()['authorization'] = await getAuth();
		return invoker(r);
	}
}

alienvspredator avatar Sep 11 '20 12:09 alienvspredator

did you find a solution to this? Having the same issue trying to await for a jwt token refresh...

guess this is a duplicate of https://github.com/grpc/grpc-web/issues/988

dhax avatar Feb 10 '21 15:02 dhax

@alienvspredator @dhax any solutions? running into the same use case also with doing JWT token refresh in the interceptor

kurnal-volt avatar Sep 24 '21 18:09 kurnal-volt

@kurnal-volt no, I am only using an unaryInterceptor with the promise based client. Doesn't look like there was any progress regarding an async streamInterceptor.

dhax avatar Sep 25 '21 12:09 dhax

@dhax could you show me what an example for a promise based unaryInterceptor is? also is there a promise based streamInterceptor?

kurnal-volt avatar Sep 26 '21 23:09 kurnal-volt

@kurnal-volt have a look at the tests, e.g.: https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/test/tsc-tests/client04.ts

dhax avatar Oct 07 '21 12:10 dhax