Hi everyone hope you are doing well.
I want to create a guard for graphql in Nestjs, but I am getting the following error.
How can I resolve this?
-- error statement --
Error: Nest can't resolve dependencies of the GqlAuthGuard (AccountService, ?). Please make sure that the argument Object at index [1] is available in the UserModule context.
-- source code --
@Injectable()
export class GqlAuthGuard
extends AuthGuard('gql-supertokens')
implements CanActivate
{
constructor(
private verifySessionOptions: VerifySessionOptions,
) {
super();
}
async canActivate(context: GqlExecutionContext): Promise
{
let err = undefined;
const ctx = GqlExecutionContext.create(context);
const [req, resp] = [ctx.getContext().req, ctx.getContext().res];
await verifySession(this.verifySessionOptions)(req, resp, (res) => {
err = res;
});
if (err || !req.session) {
throw new UnauthorizedException();
}
return true;
}
}