Skip to content

Commit 61ffc2c

Browse files
committed
fix auth generate token
1 parent 6201fe9 commit 61ffc2c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

service/src/core/auth/auth.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Header, Headers, HttpStatus, Post, Res, UseGuards } from '@nestjs/common'
1+
import { Body, Controller, Get, Headers, HttpStatus, Post, Res, UseGuards } from '@nestjs/common'
22
import { AuthService } from './auth.service'
33
import { AbstractController } from '~/_common/abstracts/abstract.controller'
44
import { Response } from 'express'

service/src/core/auth/auth.service.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,24 @@ export class AuthService extends AbstractService implements OnModuleInit {
4646
this.logger.warn('DEV MODE ENABLED !')
4747
const devTokenPath = resolve(process.cwd(), this.DEV_TOKEN_PATH)
4848
if (existsSync(devTokenPath)) {
49-
const data = JSON.parse(readFileSync(devTokenPath, 'utf-8'))
50-
this.logger.log(`TOKEN ALREADY EXIST : <${data.access_token}>`)
51-
} else {
52-
const { access_token } = await this.createTokens(new ConsoleSession(), false, {
53-
expiresIn: '1y',
54-
})
55-
writeFileSync(devTokenPath, JSON.stringify({
56-
access_token,
57-
}))
58-
59-
this.logger.log(`NEW TOKEN CREATED : <${access_token}>`)
49+
try {
50+
const data = JSON.parse(readFileSync(devTokenPath, 'utf-8'))
51+
if (data.access_token) {
52+
this.logger.log(`TOKEN ALREADY EXIST : <${data.access_token}>`)
53+
return
54+
}
55+
} catch (e) {
56+
this.logger.error(`TOKEN FILE CORRUPTED ! REGENERATING...`)
57+
}
6058
}
59+
const { access_token } = await this.createTokens(new ConsoleSession(), false, {
60+
expiresIn: '1y',
61+
})
62+
writeFileSync(devTokenPath, JSON.stringify({
63+
access_token,
64+
}))
65+
66+
this.logger.log(`NEW TOKEN CREATED : <${access_token}>`)
6167
}
6268
}
6369

0 commit comments

Comments
 (0)