Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['14', '12', '10']
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run standard
- run: npm run test
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

22 changes: 22 additions & 0 deletions auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FastifyPlugin, FastifyRequest, FastifyReply } from 'fastify';

export type FastifyAuthFunction = (
request: FastifyRequest,
reply: FastifyReply,
done: (error?: Error) => void
) => void;

declare module 'fastify' {
interface FastifyInstance {
auth(
functions: FastifyAuthFunction[],
options?: {
relation?: 'and' | 'or',
run?: 'all'
}
): void;
}
}

declare const fastifyAuth: FastifyPlugin;
export default fastifyAuth;
2 changes: 1 addition & 1 deletion fastify-auth.js → auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ function auth (functions, opts) {
}
}

module.exports = fp(checkAuth, '>=0.13.1')
module.exports = fp(checkAuth, '3.x')
2 changes: 1 addition & 1 deletion example-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function build (opts) {
fastify
.register(require('fastify-jwt'), { secret: 'supersecret' })
.register(require('fastify-leveldb'), { name: 'authdb-async' })
.register(require('./fastify-auth'))
.register(require('./auth'))
.after(routes)

fastify.decorate('verifyJWTandLevel', verifyJWTandLevel)
Expand Down
2 changes: 1 addition & 1 deletion example-composited.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function build (opts) {
const fastify = Fastify(opts)

fastify
.register(require('./fastify-auth'))
.register(require('./auth'))
.after(routes)

fastify.decorate('verifyNumber', verifyNumber)
Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function build (opts) {
fastify
.register(require('fastify-jwt'), { secret: 'supersecret' })
.register(require('fastify-leveldb'), { name: 'authdb' })
.register(require('./fastify-auth')) // just 'fastify-auth' IRL
.register(require('./auth')) // just 'fastify-auth' IRL
.after(routes)

fastify.decorate('verifyJWTandLevelDB', verifyJWTandLevelDB)
Expand Down
54 changes: 0 additions & 54 deletions fastify-auth.d.ts

This file was deleted.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"type": "git",
"url": "git+https://github.com/fastify/fastify-auth.git"
},
"main": "fastify-auth.js",
"types": "fastify-auth.d.ts",
"main": "auth.js",
"types": "auth.d.ts",
"scripts": {
"clean": "rimraf authdb",
"test": "standard && tap -J ./test/*.test.js && npm run typescript",
"typescript": "tsc --project ./test/types/tsconfig.json"
"test": "npm run test:unit && npm run test:typescript",
"standard": "standard",
"test:unit": "tap -J ./test/*.test.js",
"test:typescript": "tsd"
},
"keywords": [
"fastify",
Expand All @@ -27,23 +29,21 @@
],
"license": "MIT",
"devDependencies": {
"fastify": "^2.0.0",
"fastify-jwt": "^1.0.0",
"fastify": "^3.0.0-rc.1",
"fastify-jwt": "^2.0.0",
"fastify-leveldb": "^2.1.0",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.3",
"standard": "^14.0.0",
"tap": "^12.7.0",
"typescript": "^3.1.6"
"tsd": "^0.11.0",
"typescript": "^3.8.3"
},
"dependencies": {
"fastify-plugin": "^1.5.0",
"fastify-plugin": "^2.0.0",
"reusify": "^1.0.4"
},
"greenkeeper": {
"ignore": [
"tap",
"rimraf"
]
"tsd": {
"directory": "test"
}
}
31 changes: 31 additions & 0 deletions test/auth.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fastify, { FastifyRequest, FastifyReply } from 'fastify';
import fastifyAuth from '../auth'
import { expectType } from 'tsd';

const app = fastify();

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

app.register(fastifyAuth).after((err) => {
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)
},
], {run: 'all'});
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
]);
});
2 changes: 1 addition & 1 deletion test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { test } = require('tap')
const Fastify = require('fastify')
const fastifyAuth = require('../fastify-auth')
const fastifyAuth = require('../auth')

test('Clean status code through auth pipeline', t => {
t.plan(3)
Expand Down
23 changes: 0 additions & 23 deletions test/types/tsconfig.json

This file was deleted.

56 changes: 0 additions & 56 deletions test/types/types.test.ts

This file was deleted.