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_st
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)
fragordie
04/26/2022, 11:32 AMrp_st
04/26/2022, 11:34 AMfragordie
04/26/2022, 11:42 AMfragordie
04/26/2022, 11:43 AMfragordie
04/26/2022, 11:43 AMrp_st
04/26/2022, 11:43 AMrp_st
04/26/2022, 11:44 AMrp_st
04/26/2022, 11:44 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>(),
);
}
}
fragordie
04/26/2022, 11:50 AMfragordie
04/26/2022, 11:50 AMrp_st
04/26/2022, 11:51 AMfragordie
04/26/2022, 11:52 AMfragordie
04/26/2022, 11:52 AMts
if (ctx.res.headersSent) {
throw new GQLSTError({
message: 'RESPONSE_SENT',
type: 'RESPONSE_SENT',
});
}
fragordie
04/26/2022, 11:52 AMfragordie
04/26/2022, 11:52 AMrp_st
04/26/2022, 11:53 AMrp_st
04/26/2022, 11:53 AMfragordie
04/26/2022, 11:55 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>(),
);
}
}
fragordie
04/26/2022, 11:56 AMfragordie
04/26/2022, 11:56 AMfragordie
04/26/2022, 11:56 AMfragordie
04/26/2022, 11:56 AMfragordie
04/26/2022, 12:03 PMfragordie
04/26/2022, 12:03 PMcatch(exception: Error, host: ArgumentsHost)
fragordie
04/26/2022, 12:06 PMts
ctx.getArgByIndex(2)
fragordie
04/26/2022, 12:11 PMts
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_st
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);
}
fragordie
04/26/2022, 12:31 PMfragordie
04/26/2022, 12:32 PMfragordie
04/26/2022, 12:32 PMError: 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_st
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_st
04/26/2022, 1:22 PMrp_st
04/26/2022, 1:22 PMrp_st
04/26/2022, 1:22 PMfragordie
04/26/2022, 1:22 PMfragordie
04/26/2022, 1:23 PMrp_st
04/26/2022, 1:23 PM