This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
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.
Extract JWT from Authorization header (#59)
- Loading branch information
1 parent
fe48574
commit b0e054d
Showing
3 changed files
with
17 additions
and
53 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,36 +1,14 @@ | ||
import { | ||
Body, | ||
Controller, | ||
HttpCode, | ||
HttpStatus, | ||
Post, | ||
Res, | ||
} from '@nestjs/common'; | ||
import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common'; | ||
import { AuthService } from '../auth.service'; | ||
import { LoginDto } from '../dto'; | ||
import { Response } from 'express'; | ||
|
||
@Controller('auth/login') | ||
export class LoginController { | ||
constructor(private readonly authService: AuthService) {} | ||
|
||
@Post() | ||
@HttpCode(HttpStatus.OK) | ||
async login(@Body() dto: LoginDto, @Res() res: Response) { | ||
const jwt = await this.authService.login(dto); | ||
if (!jwt.length) { | ||
res.send({ has2FAEnabled: true }); | ||
return; | ||
} | ||
res.cookie(...jwt); | ||
res.cookie( | ||
'user_info', | ||
JSON.stringify(await this.authService.getUserPublicInfo(dto.email)), | ||
{ | ||
secure: true, | ||
sameSite: 'lax', | ||
}, | ||
); | ||
res.send({ token: jwt[1] }); | ||
async login(@Body() dto: LoginDto) { | ||
return await this.authService.login(dto); | ||
} | ||
} |
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