tommykhumarga3422
10/01/2022, 12:40 PMERROR [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
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?
Thanksrp_st
10/01/2022, 2:09 PMtommykhumarga3422
10/01/2022, 2:33 PMrp_st
10/01/2022, 2:53 PMrp_st
10/01/2022, 2:53 PMporcellus
10/02/2022, 10:10 AMAuthGuard
as @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.rp_st
10/02/2022, 3:51 PM