- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 58
 
types: extended FastifyAuthFunction type to accept async functions #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -9,13 +9,21 @@ const app = fastify() | |||||
| type Done = (error?: Error) => void | ||||||
| 
     | 
||||||
| app.register(fastifyAuth).after((_err) => { | ||||||
| // Callback tests | ||||||
| app.auth([ | ||||||
| (request, reply, done) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| expectType<Done>(done) | ||||||
| }, | ||||||
| ], { relation: 'or' }) | ||||||
| app.auth([ | ||||||
| (request, reply, done) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| expectType<Done>(done) | ||||||
| }, | ||||||
| ], { relation: 'and' }) | ||||||
| app.auth([ | ||||||
| (request, reply, done) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| 
        
          
        
         | 
    @@ -29,12 +37,123 @@ app.register(fastifyAuth).after((_err) => { | |||||
| expectType<FastifyReply>(reply) | ||||||
| expectType<Done>(done) | ||||||
| }, | ||||||
| ], { relation: 'or', run: 'all' }) | ||||||
| app.auth([ | ||||||
| (request, reply, done) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| expectType<Done>(done) | ||||||
| }, | ||||||
| ], { relation: 'and', run: 'all' }) | ||||||
| 
     | 
||||||
| // Async function tests | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ]) | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'or' }) | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'and' }) | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ], { run: 'all' }) | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'or', run: 'all' }) | ||||||
| app.auth([ | ||||||
| async (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'and', run: 'all' }) | ||||||
| 
     | 
||||||
| // Promise-based function tests | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ]) | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'or' }) | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'and' }) | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ], { run: 'all' }) | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'or', run: 'all' }) | ||||||
| app.auth([ | ||||||
| (request: FastifyRequest, reply: FastifyReply) => { | ||||||
| expectType<FastifyRequest>(request) | ||||||
| expectType<FastifyReply>(reply) | ||||||
| return Promise.resolve() | ||||||
| }, | ||||||
| ], { relation: 'and', run: 'all' }) | ||||||
| 
     | 
||||||
| // this context tests | ||||||
| app.auth([ | ||||||
| async function () { | ||||||
| expectType<FastifyInstance>(this) | ||||||
| await Promise.resolve() | ||||||
| }, | ||||||
| ]) | ||||||
| app.auth([ | ||||||
| function () { | ||||||
        
    
 | 
||||||
| function () { | |
| function (this: FastifyInstance) { | 
    
      
    
      Copilot
AI
    
    
    
      Aug 14, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async function is missing the explicit 'this: FastifyInstance' type annotation that was mentioned as necessary in the PR description. This should be 'async function (this: FastifyInstance) {' to match the requirement for TypeScript's inability to infer 'this' context in union types.
| async function () { | |
| async function (this: FastifyInstance) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async function is missing the explicit 'this: FastifyInstance' type annotation that was mentioned as necessary in the PR description. This should be 'async function (this: FastifyInstance) {' to match the requirement for TypeScript's inability to infer 'this' context in union types.