i'm new on fp-ts
, i'm trying to create a functional-like method that:
- Parse a bearer token
- Check if the user is valid using the parsed token
import { Request } from 'express';
import { either } from 'fp-ts';
import { pipe } from 'fp-ts/lib/function';
// * Parse the token
declare const parseRawToken: (rawToken: string | undefined) => either.Either<Error, string>;
// * Interface of the validate method
type MakeIsRequestAuthenticated = (
validateUserWithToken: (data: string) => Promise<either.Either<Error, void>>,
) => (request: Request) => Promise<either.Either<Error, void>>;
I want to chain these validations inside a pipe, so I tried to implement the validation by:
export const makeIsRequestAuthenticated: MakeIsRequestAuthenticated = validateUserWithToken => {
// * Validate the request
return async request => {
return pipe(
parseRawToken(request.header('Authorization')),
either.chain(validateUserWithToken)
);
};
};
but it gives my the following error:
Argument of type '(data: string) => Promise<Either<Error, void>>' is not assignable to parameter of type '(a: string) => Either<Error, void>'.
Type 'Promise<Either<Error, void>>' is not assignable to type 'Either<Error, void>'.ts(2345)
i had try replace the Promise
by a TaskEither
and some other solutions but none of them worked
I want to use the chain
or may other some method to be able to execute all these operations inside the pipe