Skip to content

Commit

Permalink
Example on how to put authentication method in its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
AshMW2724 committed Dec 28, 2023
1 parent 37867f7 commit c379471
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { WebSocketServer } from 'ws';
import { Server as HttpServer, IncomingMessage as HttpIncomingMessage, ServerResponse as HttpServerResponse } from 'http';
import indexFolder from './utils/indexFolder';
import { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
import Documentation, { APIInfoObject } from './documentation';
import { HTTPContext, RouteFile, ExpressErrorResponse, RouteConfig, RouteAuthenticationMethodWithData } from './types/httprouter';
import Documentation from './documentation';
import { HTTPContext, RouteFile, RouteConfig, RouteAuthenticationMethodWithData } from './types/httprouter';
import { HttpStatus } from 'utils/httpStatus';
import { AuthenticationMethods, MiddlewareWhen, RouteMiddleware, ServerConfig } from './types/server';

Expand Down
11 changes: 11 additions & 0 deletions test/authentication/hasPermission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Context } from '..';
import { CtxMiddlewareFunction } from '../../src/types/server';

interface Data {
where: string;
}

export const hasPermission: CtxMiddlewareFunction<Context> = (ctx, data: Data) => {
console.log(data.where);
return ctx.next();
};
4 changes: 3 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
process.chdir(__dirname);
import { Server, HTTPContext } from '../src/index';
import { hasPermission } from './authentication/hasPermission';

const context = {
test: 'test',
Expand All @@ -21,7 +22,7 @@ const api = new Server({
enabled: true,
methods: {
loggedIn: () => undefined,
hasPermission: (ctx, { penis }: { penis: boolean }) => undefined,
hasPermission,
needsBot: () => undefined,
cumInAssable: () => undefined,
},
Expand Down Expand Up @@ -70,6 +71,7 @@ const api = new Server({
// Export necessary shit
export type RouteHandler = typeof api.routeHandler<HTTPContext>;
export type RouteConfig = typeof api.routeConfig;
export type Context = typeof context;
export const authenticationMethod = api.authenticationMethod;

// Prior to starting the server, you can middleware
Expand Down

0 comments on commit c379471

Please sign in to comment.