#Google OAUTH with Fastify

1 messages · Page 1 of 1 (latest)

native pumice
#

I'm using a workaround for some time

app.getHttpAdapter()
        .getInstance()
        .addHook('onRequest', (request, reply, done) => {
            reply.setHeader = function (key, value) {
                return this.raw.setHeader(key, value);
            };
            reply.end = function () {
                this.raw.end();
            };
            request.res = reply;
            done();
        });

But since the new fastify update in nestjs v10 i'm getting some errors:

Did anyone maybe migrated this part?

quartz lodge
#

Most likely it's just a type issue and still works fine

native pumice
quartz lodge
#

Well what's the error?

native pumice
#

Property 'setHeader' does not exist on type 'FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>'. Did you mean 'getHeader'?

#

Property 'end' does not exist on type 'FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>'. Did you mean 'send'?ts(2551)

#

Property 'res' does not exist on type 'FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<...>>'.ts(2339)

native pumice
quartz lodge
#

Ah, so the annoying thing is that we're trying to add these methods so that passport can call them. Fastify doesn't originally have them, hence this workaround. You can either make use of declaration merging, or provide your own types for the reply

native pumice
quartz lodge
#

Why? Nest doesn't directly support fastify using OAuth with passport. This was literally a workaround I found for a client that I've shared

native pumice
#

Yes it's this issue

#

but also

#

Idk if it is stable

quartz lodge
#

Right, so when that happens, this workaround will no longer be needed

native pumice
#

seems well updated

#

This is the new repository

quartz lodge
#

Right, the fun thing is having to recreate the passport wrapper to actually work with both variants . I'll probably be trying to work on that soonish