FrAgOrDiE
04/26/2022, 11:29 AMts
@Injectable()
export class GQLAuthGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const ctx = GqlExecutionContext.create(context).getContext();
let err = undefined;
// You can create an optional version of this by passing {sessionRequired: false} to verifySession
await verifySession({ sessionRequired: false })(
ctx.req,
ctx.res,
(res) => {
err = res;
},
);
if (ctx.res.headersSent) {
throw new STError({
message: 'RESPONSE_SENT',
type: 'RESPONSE_SENT',
});
}
if (err) {
throw err;
}
return true;
}
}
rp
04/26/2022, 11:30 AMFrAgOrDiE
04/26/2022, 11:32 AMD:\git\evt-server\node_modules\supertokens-node\lib\build\framework\express\framework.js:36
step(generator["throw"](value));
^
TypeError: next is not a function
at D:\git\evt-server\node_modules\supertokens-node\lib\build\framework\express\framework.js:179:24
at Generator.throw (<anonymous>)
at rejected (D:\git\evt-server\node_modules\supertokens-node\lib\build\framework\express\framework.js:36:44)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
rp
04/26/2022, 11:34 AMFrAgOrDiE
04/26/2022, 11:42 AMrp
04/26/2022, 11:43 AMFrAgOrDiE
04/26/2022, 11:50 AMts
@Catch(STError)
export class SupertokensExceptionFilter implements ExceptionFilter {
handler: ErrorRequestHandler;
constructor() {
this.handler = errorHandler();
}
catch(exception: Error, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const resp = ctx.getResponse<Response>();
if (resp.headersSent) {
return;
}
this.handler(
exception,
ctx.getRequest<Request>(),
resp,
ctx.getNext<NextFunction>(),
);
}
}
rp
04/26/2022, 11:51 AMFrAgOrDiE
04/26/2022, 11:52 AMts
if (ctx.res.headersSent) {
throw new GQLSTError({
message: 'RESPONSE_SENT',
type: 'RESPONSE_SENT',
});
}
rp
04/26/2022, 11:53 AMFrAgOrDiE
04/26/2022, 11:55 AMts
@Catch(STError)
export class SupertokensExceptionFilter implements ExceptionFilter {
handler: ErrorRequestHandler;
constructor() {
this.handler = errorHandler();
}
catch(exception: Error, host: ArgumentsHost) {
if (exception instanceof GQLSTError) return; // added this
const ctx = host.switchToHttp();
const resp = ctx.getResponse<Response>();
if (resp.headersSent) {
return;
}
this.handler(
exception,
ctx.getRequest<Request>(),
resp,
ctx.getNext<NextFunction>(),
);
}
}
catch(exception: Error, host: ArgumentsHost)
ts
ctx.getArgByIndex(2)
ts
catch(exception: Error, host: ArgumentsHost) {
const context = host.getArgByIndex(2);
if (context.res.headersSent) {
return;
}
this.handler(exception, context.req, context.res, context.next);
}
context.res.headersSent is set to true, so, I get the correct response back to the client but in the server console I get this error:
Error: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:371:5)
at ServerResponse.setHeader (node:_http_outgoing:573:11)
at D:\git\evt-server\node_modules\apollo-server-express\src\ApolloServer.ts:171:19
at processTicksAndRejections (node:internal/process/task_queues:96:5)
rp
04/26/2022, 12:16 PMtype == 'RESPONSE_SENT'
and if that's true, then you just return from the error handlerFrAgOrDiE
04/26/2022, 12:31 PMts
catch(exception: Error, host: ArgumentsHost) {
if (exception.message === 'RESPONSE_SENT') return;
const context = host.getArgByIndex(2);
if (context.res.headersSent) {
return;
}
this.handler(exception, context.req, context.res, context.next);
}
Error: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:371:5)
at ServerResponse.setHeader (node:_http_outgoing:573:11)
at D:\git\evt-server\node_modules\apollo-server-express\src\ApolloServer.ts:171:19
at processTicksAndRejections (node:internal/process/task_queues:96:5)
rp
04/26/2022, 12:33 PMFrAgOrDiE
04/26/2022, 1:12 PMantiCsrfCheck: false
... do you have any idea of why? Otherwise I'm ok with github issuerp
04/26/2022, 1:22 PMFrAgOrDiE
04/26/2022, 1:22 PMrp
04/26/2022, 1:23 PM