https://supertokens.com/ logo
#support-questions
Title
# support-questions
i

ichikawa.kazuto

01/16/2023, 1:01 PM
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
You could also try using the guard as described in step 10 of the guide (https://supertokens.com/docs/passwordless/nestjs/guide#10-combine-the-decorator-and-the-guard-to-authenticate-users): by passing an instance of the class to
UseGuards
instead of passing the class itself.