Skip to content

Commit

Permalink
'.'
Browse files Browse the repository at this point in the history
  • Loading branch information
ManucherKM committed Oct 17, 2023
1 parent e771d72 commit a24fa9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/jwt/jwt.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class JwtController {
async getNewAccessToken(@Req() req: Request) {
try {
const refreshToken = req.cookies['refreshToken']

return await this.jwtService.getNewAccessToken(refreshToken)
} catch (e) {
throw new HttpException({ message: e.message }, HttpStatus.BAD_REQUEST)
Expand Down
13 changes: 3 additions & 10 deletions src/jwt/jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class JwtService {
throw new BadRequestException('Invalid token.')
}

return this.getAccessToken(dataToken)
return {
accessToken: this.getAccessToken(dataToken),
}
}

getAccessToken(payload: IDataToken) {
Expand All @@ -86,15 +88,6 @@ export class JwtService {
const foundToken = await this.jwtModel.findOne({ userId: payload.userId })

if (foundToken) {
const [isValid, _] = await this.validateToken(
foundToken.refreshToken,
'refresh',
)

if (isValid) {
return foundToken.refreshToken
}

const token = this.getRefreshToken(payload)

foundToken.refreshToken = token
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import cookieParser from 'cookie-parser'
import * as express from 'express'
import { join } from 'path'
import { AppModule } from './app.module'

const PORT = process.env.PORT || 5000
Expand All @@ -19,7 +21,9 @@ async function bootstrap() {

app.use(cookieParser())

app.enableCors({ origin: '*' })
app.use('/uploads', express.static(join(__dirname, '..', 'uploads')))

app.enableCors({ credentials: true, origin: 'http://localhost:5173' })

const config = new DocumentBuilder()
.setTitle('Cloud storage API')
Expand Down

0 comments on commit a24fa9d

Please sign in to comment.