Skip to content
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

build(deps-dev): replace standard with neostandard #239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![CI](https://github.com/fastify/fastify-auth/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify/auth.svg?style=flat)](https://www.npmjs.com/package/@fastify/auth)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

This module does not provide an authentication strategy, but it provides a very fast utility to handle authentication (and multiple strategies) in your routes, without adding overhead.
Check out a complete example [here](test/example.js).
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"types": "types/index.d.ts",
"scripts": {
"clean": "rimraf authdb",
"lint": "standard",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "c8 --100 node --test"
Expand All @@ -43,8 +43,8 @@
"@types/node": "^22.0.0",
"c8": "^10.1.2",
"fastify": "^5.0.0",
"neostandard": "^0.11.9",
"rimraf": "^6.0.1",
"standard": "^17.1.0",
"tsd": "^0.31.1"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FastifySchema,
RouteGenericInterface,
preHandlerHookHandler
} from 'fastify';
} from 'fastify'

declare module 'fastify' {
interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
Expand Down Expand Up @@ -37,7 +37,7 @@ declare namespace fastifyAuth {
request: Request,
reply: Reply,
done: (error?: Error) => void
) => void;
) => void

/**
* @link [`fastify-auth` options documentation](https://github.com/fastify/fastify-auth#options)
Expand All @@ -55,5 +55,5 @@ declare namespace fastifyAuth {
export { fastifyAuth as default }
}

declare function fastifyAuth(...params: Parameters<FastifyAuth>): ReturnType<FastifyAuth>
declare function fastifyAuth (...params: Parameters<FastifyAuth>): ReturnType<FastifyAuth>
export = fastifyAuth
78 changes: 39 additions & 39 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import fastify, { FastifyInstance, FastifyReply, FastifyRequest, preHandlerHookHandler } from 'fastify';
import fastify, { FastifyInstance, FastifyReply, FastifyRequest, preHandlerHookHandler } from 'fastify'
import fastifyAuth from '..'
import { expectType } from 'tsd';
import { expectType } from 'tsd'
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
import { JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts'

const app = fastify();
const app = fastify()

type Done = (error?: Error) => void

app.register(fastifyAuth).after((err) => {

Check failure on line 11 in types/index.test-d.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected error to be handled
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
], {relation: 'or'});
], { relation: 'or' })
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
], {run: 'all'});
], { run: 'all' })
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
]);
])
app.auth([
function (request, reply, done) {
expectType<FastifyInstance>(this)
},
]);
const auth = app.auth([(request, reply, done) => {}]);
expectType<preHandlerHookHandler>(auth);
app.get('/secret', {preHandler: auth}, (request, reply) => {});
app.get('/private', {preHandler: [auth]}, (request, reply) => {});
});
])
const auth = app.auth([(request, reply, done) => {}])
expectType<preHandlerHookHandler>(auth)
app.get('/secret', { preHandler: auth }, (request, reply) => {})
app.get('/private', { preHandler: [auth] }, (request, reply) => {})
})

const typebox = fastify().withTypeProvider<TypeBoxTypeProvider>()
typebox.register(fastifyAuth)
Expand All @@ -59,9 +59,9 @@
handler: () => {}
})

declare module "fastify" {
declare module 'fastify' {
interface FastifyRequest {
identity: {actorId: string};
identity: { actorId: string };
}

interface FastifyInstance {
Expand All @@ -74,44 +74,44 @@
async (
request: FastifyRequest<{
Params: { userId: string }
}>,
}>
): Promise<void> => {
const { actorId } = request.identity;
const isOwner = actorId === request.params.userId;
const { actorId } = request.identity
const isOwner = actorId === request.params.userId

if (isOwner) {
return;
return
}

fastify.log.warn("Actor should not be able to see this route");
fastify.log.warn('Actor should not be able to see this route')

throw new Error(request.params.userId);
};
throw new Error(request.params.userId)
}

async function usersController(fastify: FastifyInstance): Promise<void> {
async function usersController (fastify: FastifyInstance): Promise<void> {

Check failure on line 91 in types/index.test-d.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

'usersController' is defined but never used
Fdawgs marked this conversation as resolved.
Show resolved Hide resolved
fastify.patch<{
Params: { userId: string };
Body: { name: string };
}>(
"/:userId",
'/:userId',
{
onRequest: fastify.auth([
usersMutationAccessPolicy(fastify),
]),
},
async (req, res) => ({ success: true }),
);
async (req, res) => ({ success: true })
)
}

async function usersControllerV2(fastify: FastifyInstance): Promise<void> {
async function usersControllerV2 (fastify: FastifyInstance): Promise<void> {

Check failure on line 106 in types/index.test-d.ts

View workflow job for this annotation

GitHub Actions / test / Lint Code

'usersControllerV2' is defined but never used
Fdawgs marked this conversation as resolved.
Show resolved Hide resolved
fastify.patch<{
Params: { userId: string };
Body: { name: string };
}>(
"/:userId",
'/:userId',
{
onRequest: usersMutationAccessPolicy(fastify),
},
async (req, res) => ({ success: true }),
);
}
async (req, res) => ({ success: true })
)
}
Loading