-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Login Refresh Token to keep Users Logged In. Fixes Issue[1260] #1346
base: dev
Are you sure you want to change the base?
Changes from all commits
d8a85b5
1ea85bd
e321f7a
15ea115
fb96c5f
547a65e
f0d3b87
bd0f897
b91b39a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit $1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
services: | ||
postgres: | ||
container_name: postgres-boiler | ||
image: postgres:latest | ||
ports: | ||
- '5432:5432' | ||
environment: | ||
- POSTGRES_USER=${DB_USERNAME} | ||
- POSTGRES_PASSWORD=${DB_PASSWORD} | ||
- POSTGRES_DB=${DB_DATABASE} | ||
volumes: | ||
- ./data/db:/var/lib/postgresql/data | ||
restart: always | ||
|
||
adminer: | ||
image: adminer | ||
container_name: adminer-boiler | ||
ports: | ||
- '8080:8080' | ||
restart: always | ||
depends_on: | ||
- postgres | ||
|
||
redis: | ||
image: redis:latest | ||
container_name: redis-boiler | ||
ports: | ||
- '6379:6379' | ||
command: ['redis-server', '--appendonly', 'yes'] | ||
volumes: | ||
- redis_data:/data | ||
restart: always | ||
|
||
volumes: | ||
data: | ||
redis_data: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import { | |
ApiUnauthorizedResponse, | ||
} from '@nestjs/swagger'; | ||
import * as SYS_MSG from '@shared/constants/SystemMessages'; | ||
import { Body, Controller, HttpCode, Post, Req, Request, Patch } from '@nestjs/common'; | ||
import { Body, Controller, HttpCode, Post, Req, Res, Request, Patch } from '@nestjs/common'; | ||
import { CreateUserDTO } from './dto/create-user.dto'; | ||
import { skipAuth } from '@shared/helpers/skipAuth'; | ||
import AuthenticationService from './auth.service'; | ||
|
@@ -33,6 +33,7 @@ import { UpdatePasswordDto } from './dto/updatePasswordDto'; | |
import { LoginErrorResponseDto } from './dto/login-error-dto'; | ||
import { UpdateUserPasswordResponseDTO } from './dto/update-user-password.dto'; | ||
import { CustomHttpException } from '@shared/helpers/custom-http-filter'; | ||
import { Response, Request as RequestExpress } from 'express'; | ||
|
||
@ApiTags('Authentication') | ||
@Controller('auth') | ||
|
@@ -76,8 +77,21 @@ export default class RegistrationController { | |
@ApiResponse({ status: 200, description: 'Login successful', type: LoginResponseDto }) | ||
@ApiUnauthorizedResponse({ description: 'Invalid credentials', type: LoginErrorResponseDto }) | ||
@HttpCode(200) | ||
async login(@Body() loginDto: LoginDto): Promise<LoginResponseDto | { status_code: number; message: string }> { | ||
return this.authService.loginUser(loginDto); | ||
async login( | ||
@Body() loginDto: LoginDto, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove these comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
@Req() req: RequestExpress, | ||
@Res({ passthrough: true }) res: Response | ||
): Promise<LoginResponseDto | { status_code: number; message: string }> { | ||
return this.authService.loginUser(loginDto, req, res); | ||
} | ||
|
||
@Post('refresh-token') | ||
@ApiOperation({ summary: 'Refresh Access Token' }) | ||
@ApiResponse({ status: 200, description: 'New access token issued' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
@HttpCode(200) | ||
async refreshToken(@Req() req: RequestExpress, @Res({ passthrough: true }) res: Response) { | ||
return this.authService.refreshToken(req, res); | ||
} | ||
|
||
@skipAuth() | ||
|
@@ -173,4 +187,12 @@ export default class RegistrationController { | |
public async resetPassword(@Body() updatePasswordDto: UpdatePasswordDto) { | ||
return this.authService.updateForgotPassword(updatePasswordDto); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logout is being handled on the FE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay |
||
@Post('logout') | ||
@ApiOperation({ summary: 'Logout user' }) | ||
@ApiResponse({ status: 200, description: 'User successfully logged out' }) | ||
@HttpCode(200) | ||
async logout(@Res({ passthrough: true }) res: Response) { | ||
return this.authService.logout(res); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dev": "PROFILE=local was unable to run, so I had to use
"npx ts-node-dev -r dotenv/config --respawn src/main",