-
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.
Merge pull request #126 from boostcampwm2023/feature-be-#125
[BE] feat#125 Guard를 설정한다
- Loading branch information
Showing
4 changed files
with
45 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class CommandGuard implements CanActivate { | ||
canActivate(context: ExecutionContext): boolean { | ||
const request = context.switchToHttp().getRequest<Request>(); | ||
const command = request.body['command']; | ||
return typeof command === 'string' && command.startsWith('git'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
||
export const SessionId = createParamDecorator( | ||
(data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.cookies['sessionId']; | ||
}, | ||
); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
|
||
/** | ||
* @description session guard | ||
* @returns {boolean} | ||
* check if sessionId exists | ||
* @dependency cookie-parser | ||
*/ | ||
@Injectable() | ||
export class SessionGuard implements CanActivate { | ||
canActivate(context: ExecutionContext): boolean { | ||
const request = context.switchToHttp().getRequest<Request>(); | ||
// cookie-parser must be used before this guard | ||
return request['cookies'].sessionId; | ||
} | ||
} |