Hi, I'm new to SuperTokens and try to implement S...
# support-questions-legacy
t
Hi, I'm new to SuperTokens and try to implement SuperTokens in NestJS. But NestJS showed error like below
ERROR [ExceptionHandler] Nest can't resolve dependencies of the AuthGuard (?). Please make sure that the argument Object at index [0] is available in the AppModule context.
Below is my auth.guard.ts codes
Copy code
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Error as STError } from 'supertokens-node';

import { verifySession } from 'supertokens-node/recipe/session/framework/express';
import { VerifySessionOptions } from 'supertokens-node/recipe/session';

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private readonly verifyOptions?: VerifySessionOptions) {}

  async canActivate(context: ExecutionContext): Promise<boolean> {
    const ctx = context.switchToHttp();

    let err = undefined;
    const resp = ctx.getResponse();
    // You can create an optional version of this by passing {sessionRequired: false} to verifySession
    await verifySession(this.verifyOptions)(ctx.getRequest(), resp, (res) => {
      err = res;
    });

    if (resp.headersSent) {
      throw new STError({
        message: 'RESPONSE_SENT',
        type: 'RESPONSE_SENT'
      });
    }

    if (err) {
      throw err;
    }

    return true;
  }
}
Did I missed something? Thanks
r
Hey! Did you follow our guide for nestjs?
t
Yes, I followed your guide
r
Maybe @porcellus can help out.
Since it’s the weekend, expect help by Monday please.
p
Hi, you can use this version of the
AuthGuard
as
Copy code
@UseGuards(new AuthGuard())
I'll update the code in the guide in a bit to be a bit more flexible, which will enable usage without instantiating it yourself.
r
Also, checkout the nestjs example app that we have. You can set it up by running npx create-supertokens-app