This commit is contained in:
Tomek Łaziuk
2017-12-08 18:25:34 +01:00
parent 1b079f306b
commit c47037f15d
2 changed files with 3 additions and 9 deletions
+1 -4
View File
@@ -21,8 +21,7 @@ import * as passport from "passport";
declare module "koa" {
interface Context {
login(user: any): Promise<void>;
login(user: any, options: any): Promise<void>;
login(user: any, options?: any): Promise<void>;
logIn: Context["login"];
logout(): void;
@@ -33,9 +32,7 @@ declare module "koa" {
}
}
declare namespace KoaPassport {
class KoaPassport {
use(strategy: passport.Strategy): this;
use(name: string, strategy: passport.Strategy): this;
+2 -5
View File
@@ -2,13 +2,11 @@ import * as Koa from 'koa';
import * as passport from 'koa-passport';
const app = new Koa();
let ctx: Koa.Context;
app.use(passport.initialize());
app.use(passport.session());
app.use(async (ctx: Koa.Context): Promise<void> => {
app.use(async (ctx): Promise<void> => {
ctx.isAuthenticated();
ctx.isUnauthenticated();
ctx.login({});
@@ -16,8 +14,7 @@ app.use(async (ctx: Koa.Context): Promise<void> => {
ctx.state.user;
});
app.use(async (ctx: Koa.Context, next: () => Promise<any>) => {
app.use(async (ctx, next) => {
return passport.authenticate('local', (user: any, info: any, status: any) => {
if (user === false) {
ctx.status = 401;