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;
}
}
r
rp
01/16/2023, 1:27 PM
hey @ichikawa.kazuto
@porcellus can help here
p
porcellus
01/16/2023, 3:15 PM
Hi
The issue here is how this guard (and the verifySessionOptions parameter of the constructor) mixes with the AuthGuard base class you are extending
if you remove that parameter (or the entire constructor, because it doesn't do anything without taking that parameter), it should resolve this issue but then you have to define verifySessionOptions in canActivate