Skip to content

Commit

Permalink
fix: isAuthenticated missing this (#3617)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Feb 2, 2024
1 parent 3fefcc7 commit de17e14
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/passport/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare module '@midwayjs/koa/dist/interface' {
isAuthenticated(): boolean;
isUnauthenticated(): boolean;
login(): Promise<void>;
logout(): void;
logout(): Promise<void>;
}
}

Expand All @@ -28,7 +28,7 @@ declare module '@midwayjs/web/dist/interface' {
isAuthenticated(): boolean;
isUnauthenticated(): boolean;
login(): Promise<void>;
logout(): void;
logout(): Promise<void>;
}
}

Expand All @@ -40,7 +40,7 @@ declare module '@midwayjs/faas/dist/interface' {
isAuthenticated(): boolean;
isUnauthenticated(): boolean;
login(): Promise<void>;
logout(): void;
logout(): Promise<void>;
}
}

Expand All @@ -50,7 +50,7 @@ declare module '@midwayjs/express/dist/interface' {
// These declarations are merged into express's Request type
login(user: any, done: (err: any) => void): void;
login(user: any, options: any, done: (err: any) => void): void;
logout(): void;
logout(): Promise<void>;
isAuthenticated(): boolean;
isUnauthenticated(): boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/passport/src/passport/passport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export function PassportMiddleware(
};
req.isAuthenticated = () => {
const property = this.passport.getUserProperty();
return !!this[property];
return !!req[property];
};
req.isUnauthenticated = () => {
return !req.isAuthenticated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class TestPackagesController {
this.req.user?.username === 'admin' &&
this.req.user?.password === '123'
) {
return 'success';
return this.req.isAuthenticated() ? 'success': 'fail';
}

return 'fail';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class TestPackagesController {
this.ctx.state.user?.username === 'admin' &&
this.ctx.state.user?.password === '123'
) {
return 'success';
return this.ctx.isAuthenticated() ? 'success': 'fail';
}

return 'fail';
Expand Down

0 comments on commit de17e14

Please sign in to comment.