Skip to content

Commit 49d5342

Browse files
committed
fix: access_token expire time in cookie and jwt
1 parent deef5a3 commit 49d5342

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

packages/velog-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"graphql-scalars": "^1.22.2",
6161
"inquirer": "^9.2.12",
6262
"ioredis": "^5.3.2",
63-
"jsonwebtoken": "^9.0.0",
63+
"jsonwebtoken": "^9.0.2",
6464
"lru-cache": "^10.0.0",
6565
"marked": "^8.0.0",
6666
"mercurius": "^13.0.0",

packages/velog-server/src/common/plugins/global/authPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
1010
fastify.decorateRequest('user', null)
1111
fastify.addHook('preHandler', async (request, reply) => {
1212
if (request.url.includes('/auth/logout')) return
13+
1314
let accessToken: string | undefined = request.cookies['access_token']
1415
const refreshToken: string | undefined = request.cookies['refresh_token']
1516
const authorization = request.headers['authorization']
17+
1618
try {
1719
if (!accessToken && authorization) {
1820
accessToken = authorization.split('Bearer ')[1]

packages/velog-server/src/lib/jwt/JwtService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class JwtService {
6363
},
6464
{
6565
subject: 'access_token',
66-
expiresIn: '1h',
66+
expiresIn: '24h',
6767
},
6868
)
6969

@@ -100,7 +100,7 @@ export class JwtService {
100100
},
101101
{
102102
subject: 'access_token',
103-
expiresIn: '1h',
103+
expiresIn: '24h',
104104
},
105105
)
106106

packages/velog-server/src/routes/auth/v3/social/SocialController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class SocialController implements Controller {
131131
if (user) {
132132
const tokens = await this.jwt.generateUserToken(user.id)
133133
this.cookie.setCookie(reply, 'access_token', tokens.accessToken, {
134-
maxAge: Time.ONE_HOUR_IN_MS,
134+
maxAge: Time.ONE_HOUR_IN_MS * 24,
135135
})
136136
this.cookie.setCookie(reply, 'refresh_token', tokens.refreshToken, {
137137
maxAge: Time.ONE_DAY_IN_MS * 30,
@@ -255,7 +255,7 @@ export class SocialController implements Controller {
255255

256256
const tokens = await this.jwt.generateUserToken(user.id)
257257
this.cookie.setCookie(reply, 'access_token', tokens.accessToken, {
258-
maxAge: Time.ONE_HOUR_IN_MS,
258+
maxAge: Time.ONE_HOUR_IN_MS * 24,
259259
})
260260
this.cookie.setCookie(reply, 'refresh_token', tokens.refreshToken, {
261261
maxAge: Time.ONE_DAY_IN_MS * 30,

packages/velog-server/src/services/UserService/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class UserService implements Service {
144144
)
145145

146146
this.cookie.setCookie(ctx.reply, 'access_token', tokens.accessToken, {
147-
maxAge: Time.ONE_HOUR_IN_MS,
147+
maxAge: Time.ONE_HOUR_IN_MS * 24,
148148
})
149149
this.cookie.setCookie(ctx.reply, 'refresh_token', tokens.refreshToken, {
150150
maxAge: Time.ONE_DAY_IN_MS * 30,

0 commit comments

Comments
 (0)