-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9476881
commit 67e1026
Showing
5 changed files
with
35 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Injectable() | ||
export class LoginGuard extends AuthGuard('oidc') { | ||
constructor(private readonly configService: ConfigService) { | ||
super(); | ||
} | ||
|
||
async canActivate(context: ExecutionContext) { | ||
console.log('plep 1', context); | ||
try { | ||
const result = (await super.canActivate(context)) as boolean; | ||
const request = context.switchToHttp().getRequest(); | ||
await super.logIn(request); | ||
return result; | ||
} catch (e) { | ||
console.log(e); | ||
const response = context.switchToHttp().getResponse(); | ||
response.redirect( | ||
this.configService.get('WEBSITE_URL') + '?error=unauthorized', | ||
); | ||
} | ||
console.log('plep 2'); | ||
const request = context.switchToHttp().getRequest(); | ||
console.log('plep 3'); | ||
await super.logIn(request); | ||
console.log('plep 4'); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters