Initial commit - version 1.0.0
This commit is contained in:
18
src/middleware/initialize.ts
Normal file
18
src/middleware/initialize.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Middleware } from 'koa';
|
||||
import { GatekeeperUser } from './types/GatekeeperUser';
|
||||
|
||||
declare module 'koa' {
|
||||
interface ExtendableContext {
|
||||
user: GatekeeperUser | null;
|
||||
isAuthenticated(): boolean;
|
||||
isUnauthenticated(): boolean;
|
||||
logout(): void;
|
||||
}
|
||||
}
|
||||
|
||||
export const initialize: Middleware = (ctx) => {
|
||||
ctx.user = null;
|
||||
ctx.isAuthenticated = () => !!ctx.user;
|
||||
ctx.isUnauthenticated = () => !ctx.user;
|
||||
ctx.logout = () => (ctx.user = null);
|
||||
};
|
||||
Reference in New Issue
Block a user